Re: [問題] 小畫家功能

作者: ideaup (ideaupsoho)   2019-07-18 20:06:23
※ 引述《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);
}
作者: Litfal (Litfal)   2019-07-18 23:50:00
原原PO只是搞不清楚Graphics是怎麼回事啦,你要他改用WinAPI也太狠,雖然xor繪圖很好用
作者: ideaup (ideaupsoho)   2019-07-19 08:19:00
LastRect.Width+=X.Height+=Y,只是copy 以前的給他參考
作者: amen1387 (MyBad)   2019-07-19 19:07:00
跨攏謀 哈哈哈哈也謝謝謝謝i大

Links booklink

Contact Us: admin [ a t ] ucptt.com