Re: [問題] 小畫家功能

看板C_Sharp作者 (ideaupsoho)時間4年前 (2019/07/18 20:06), 編輯推噓2(203)
留言5則, 3人參與, 4年前最新討論串3/4 (看更多)
※ 引述《amen1387 (MyBad)》之銘言: : ※ 引述《fantoccini (失控的顏色)》之銘言: : : 這幾天為了寫視窗開始學C# : : 再練習的時候遇到一個問題 : : 例如我要畫一個矩形 : : 當Mouse按下後 然後移動 然後放開 : : 最後的結果是一個矩形 但是 : : 我的滑鼠在移動的過程中 無法看出 : : 這個矩形跟隨著你的滑鼠移動 : : 簡單的說 就是小畫家 圈選矩形的那個功能 : : 感覺上是要一直重繪 不知道是不是這樣 : 我把drawline寫在mouse_up的話,就跟原本樓主的問題一樣,但試著寫在mouse_move他就 : 會一直出現 : 我現在有想到的方式是在mousedown的時候把picture box擷取起來 : Bitmap lastimage=new Bitmap(picturebox1.width,picturebox1.height); : Garphcs Imagegrapics=Graphics.FromImage(lastimage); : 然後在mousemove時 : Graphics p =pictureBox1.CreateGraphics(); : if(e.Button==MouseButton.Left) : { : p=image graphics; : p.DrawLine(pen1,downX,downY,e.X,e.Y); : } ======================== [DllImport("user32.dll", EntryPoint="DrawFocusRect")] public static extern bool DrawFocusRect(IntPtr hdc,ref RECT rc); [DllImport("gdi32.dll", EntryPoint="SetROP2")] public static extern int SetROP2(IntPtr hdc, int mode); // graph=PictureBox.CreateGraphics(); Image1_MouseMove(object sender, MouseEventArgs e) { X=e.X;Y=e.Y; IntPtr hdc = graph.GetHdc(); SetROP2(hdc, CurrPenMode); DrawFocusRect(hdc, ref LastRect); LastRect.X+=X.LastRect.Y+=Y; IntPtr hdc = graph.GetHdc(); SetROP2(hdc, CurrPenMode); DrawFocusRect(hdc, ref LastRect); } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.118.137.146 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1563451585.A.13E.html

07/18 23:50, 4年前 , 1F
原原PO只是搞不清楚Graphics是怎麼回事啦,你要他改用
07/18 23:50, 1F

07/18 23:50, 4年前 , 2F
WinAPI也太狠,雖然xor繪圖很好用
07/18 23:50, 2F

07/19 08:19, 4年前 , 3F
LastRect.Width+=X.Height+=Y,只是copy 以前的給他參考
07/19 08:19, 3F

07/19 19:07, 4年前 , 4F
跨攏謀 哈哈哈哈
07/19 19:07, 4F

07/19 19:07, 4年前 , 5F
也謝謝謝謝i大
07/19 19:07, 5F
文章代碼(AID): #1TC6314- (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1TC6314- (C_Sharp)