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