作者ideaup (ideaupsoho)
看板C_Sharp
标题Re: [问题] 小画家功能
时间Thu Jul 18 20:06:23 2019
※ 引述《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://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1563451585.A.13E.html
1F:推 Litfal: 原原PO只是搞不清楚Graphics是怎麽回事啦,你要他改用 07/18 23:50
2F:→ Litfal: WinAPI也太狠,虽然xor绘图很好用 07/18 23:50
3F:→ ideaup: LastRect.Width+=X.Height+=Y,只是copy 以前的给他参考 07/19 08:19
4F:推 amen1387: 跨拢谋 哈哈哈哈 07/19 19:07
5F:→ amen1387: 也谢谢谢谢i大 07/19 19:07