-2
我有一個包含多個圖片框的面板。圖片框圖像閃爍
我想給用戶選擇任何圖片框的任何部分的選項。
用戶將通過鼠標進行選擇。
我想繪製一個半透明的矩形的圖片框,而鼠標移動的選擇。
代碼工作正常,但矩形閃爍。 我想停止閃爍。
我嘗試使用how to stop flickering C# winforms
而且雙緩衝,使用How to force graphic to be redrawn with the invalidate method
但不工作添加Invalide。請幫忙。
我的代碼:
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(矩形);' –
@LeiYang繪製的矩形是缺乏透明度和不消失鼠標向上。 –
我想你需要在'Paint'事件中繪製所有/部分,並以這種方式可以在其他按鈕事件中調用'Invalidate'。 –