Csharp/C#教程:C#如何在面板上绘制橡皮筋选择矩形,就像在Windows资源管理器中使用的一样?分享


C#如何在面板上绘制橡皮筋选择矩形,就像在Windows资源管理器中使用的一样?

我有一个带有一些用户控件的Flow Layout面板。 我想使用鼠标选择这些控件,就像在Windows文件浏览器中使用的一样。 我试过这些: https : //support.microsoft.com/en-us/kb/314945但是它非常闪烁而没用(我可能错了,请指正)。 任何好的例子请。

如果问题只是闪烁。 您可能希望将Forms双缓冲区属性设置为true。

绘制橡皮筋矩形是这样的:

private void panel1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { panel1.Refresh(); using (Graphics g = panel4.CreateGraphics()) { Rectangle rect = GetRectangle(mdown, e.Location); g.DrawRectangle(Pens.Red, rect); } } } private void panel1_MouseDown(object sender, MouseEventArgs e) { mdown = e.Location; } 

它使用辅助函数:

 static public Rectangle GetRectangle(Point p1, Point p2) { return new Rectangle(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y), Math.Abs(p1.X - p2.X), Math.Abs(p1.Y - p2.Y)); } 

我没有得到任何闪烁。 如果你这样做,也许你已经编写了Paint evetn,你可能想要使用双缓冲Panel

上述就是C#学习教程:C#如何在面板上绘制橡皮筋选择矩形,就像在Windows资源管理器中使用的一样?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 class DrawPanel : Panel { public DrawPanel() { DoubleBuffered = true; } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1007411.html

(0)
上一篇 2021年12月29日
下一篇 2021年12月29日

精彩推荐