移动用户控件时出现图形错误 (c# win7)
Graphical error while moving usercontrol (c# win7)
我在移动控件时在窗体上绘制用户控件时遇到问题。
向右或向下移动控件的背景会变短。
我的控制
public class DotPanel : Control
{
public DotPanel()
{
this.DoubleBuffered = true;
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(Color.Yellow),new Rectangle(this.Location,this.Size));
}
}
主窗体只是将用户控件放在指定位置并提供鼠标 down/move/up 事件来进行移动
基本上是这样>>
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mouseX = e.X;
mouseY = e.Y;
panelX = dp1.Left;
panelY = dp1.Top;
moving = true;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (moving)
{
dp1.Left = panelX + e.X - mouseX;
dp1.Top = panelY + e.Y - mouseY;
this.Invalidate(true);
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
moving = false;
this.Invalidate(true);
}
提前感谢您提供任何线索...
覆盖的油漆是问题所在。
将 this.Size 和 this.Location 换成 ClientRectangle.Size 和 ClientRectangle.Location 有效...
我在移动控件时在窗体上绘制用户控件时遇到问题。 向右或向下移动控件的背景会变短。
我的控制
public class DotPanel : Control
{
public DotPanel()
{
this.DoubleBuffered = true;
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(Color.Yellow),new Rectangle(this.Location,this.Size));
}
}
主窗体只是将用户控件放在指定位置并提供鼠标 down/move/up 事件来进行移动
基本上是这样>>
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mouseX = e.X;
mouseY = e.Y;
panelX = dp1.Left;
panelY = dp1.Top;
moving = true;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (moving)
{
dp1.Left = panelX + e.X - mouseX;
dp1.Top = panelY + e.Y - mouseY;
this.Invalidate(true);
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
moving = false;
this.Invalidate(true);
}
提前感谢您提供任何线索...
覆盖的油漆是问题所在。 将 this.Size 和 this.Location 换成 ClientRectangle.Size 和 ClientRectangle.Location 有效...