大家好:
我使用如下代码,实现鼠标拖动画虚线框问题,但是鼠标在移动时,虚线框不断闪烁,不知如何处理,谢谢#region 框选对象
bool MouseIsDown = false;
Rectangle MouseRect = Rectangle.Empty;
void frmMain_MouseUp(object sender, MouseEventArgs e)
{
this.FileListFlowLayoutPanel.Capture = false;
Cursor.Clip = Rectangle.Empty;
MouseIsDown = false;
DrawRectangle();
MouseRect = Rectangle.Empty;
}
void frmMain_MouseMove(object sender, MouseEventArgs e)
{
if (MouseIsDown)
ResizeToRectangle(e.Location);
}
void frmMain_MouseDown(object sender, MouseEventArgs e)
{
MouseIsDown = true;
DrawStart(e.Location);
}
private void ResizeToRectangle(Point p)
{
DrawRectangle();
MouseRect.Width = p.X - MouseRect.Left;
MouseRect.Height = p.Y - MouseRect.Top;
DrawRectangle();
}
private void DrawRectangle()
{
Rectangle rect = this.FileListFlowLayoutPanel.RectangleToScreen(MouseRect);
ControlPaint.DrawReversibleFrame(rect, Color.White, FrameStyle.Dashed);
}
private void DrawStart(Point StartPoint)
{
this.FileListFlowLayoutPanel.Capture = true;
Cursor.Clip = this.FileListFlowLayoutPanel.RectangleToScreen(new Rectangle(0, 0, ClientSize.Width, ClientSize.Height));
MouseRect = new Rectangle(StartPoint.X, StartPoint.Y, 0, 0);
}
#endregion
我使用如下代码,实现鼠标拖动画虚线框问题,但是鼠标在移动时,虚线框不断闪烁,不知如何处理,谢谢#region 框选对象
bool MouseIsDown = false;
Rectangle MouseRect = Rectangle.Empty;
void frmMain_MouseUp(object sender, MouseEventArgs e)
{
this.FileListFlowLayoutPanel.Capture = false;
Cursor.Clip = Rectangle.Empty;
MouseIsDown = false;
DrawRectangle();
MouseRect = Rectangle.Empty;
}
void frmMain_MouseMove(object sender, MouseEventArgs e)
{
if (MouseIsDown)
ResizeToRectangle(e.Location);
}
void frmMain_MouseDown(object sender, MouseEventArgs e)
{
MouseIsDown = true;
DrawStart(e.Location);
}
private void ResizeToRectangle(Point p)
{
DrawRectangle();
MouseRect.Width = p.X - MouseRect.Left;
MouseRect.Height = p.Y - MouseRect.Top;
DrawRectangle();
}
private void DrawRectangle()
{
Rectangle rect = this.FileListFlowLayoutPanel.RectangleToScreen(MouseRect);
ControlPaint.DrawReversibleFrame(rect, Color.White, FrameStyle.Dashed);
}
private void DrawStart(Point StartPoint)
{
this.FileListFlowLayoutPanel.Capture = true;
Cursor.Clip = this.FileListFlowLayoutPanel.RectangleToScreen(new Rectangle(0, 0, ClientSize.Width, ClientSize.Height));
MouseRect = new Rectangle(StartPoint.X, StartPoint.Y, 0, 0);
}
#endregion
或者
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);大概是这样,有些单词可能拼的不对