【发布时间】:2017-05-18 06:35:29
【问题描述】:
我有一个包含多个图片框的面板。
我想让用户选择任何图片框的任何部分。
用户将通过鼠标选择它。
我想在图片框上绘制一个半透明的矩形,同时鼠标根据选择移动。
代码运行正常,但矩形闪烁。 我想停止闪烁。
我尝试使用 how to stop flickering C# winforms 进行双缓冲
另外,使用How to force graphic to be redrawn with the invalidate method添加了无效
但不工作。请帮忙。
我的代码:
private Brush selectionBrush = new SolidBrush(Color.FromArgb(70, 76, 255, 0));
private void Picture_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
PictureBox pb = (PictureBox)(sender);
Point tempEndPoint = e.Location;
Rect.Location = new Point(
Math.Min(RecStartpoint.X, tempEndPoint.X),
Math.Min(RecStartpoint.Y, tempEndPoint.Y));
Rect.Size = new Size(
Math.Abs(RecStartpoint.X - tempEndPoint.X),
Math.Abs(RecStartpoint.Y - tempEndPoint.Y));
pb.CreateGraphics().FillRectangle(selectionBrush, Rect);
pb.Invalidate(Rect);
}
【问题讨论】:
-
如果你删除
pb.Invalidate(Rect);会怎样 -
@LeiYang 绘制的矩形没有透明度,鼠标上移也不会消失。
-
我猜你需要在
Paint事件中绘制全部/部分,这样你就可以在其他按钮事件中调用Invalidate。 -
最好在 Paint handler 中进行绘画作品。你应该改变你的方法。
-
你昨天问的那个问题呢?我在
MouseUp上给你example how to clear rectangle 的那个?在有人给你写申请之前,你会一直问问题吗?
标签: c# image winforms visual-studio picturebox