我一直在使用doublebuffered面板将图像绘制到自己身上,但是当我移动一个pictureBox时,它会闪烁和滞后。
我一直用于移动pictureBoxes的代码是:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
panel1.Invalidate();
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
pictureBox1.Left += (e.X - x);
pictureBox1.Top += (e.Y - y);
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(pictureBox2.BackgroundImage, new Rectangle(pictureBox2.Location, pictureBox2.Size));
}如您所见,不可见的pictureBox2被绘制到双缓冲面板。然而,当我移动pictureBox1时,它会在面板上闪烁。是的,我一直在使用()面板
我使用的双缓冲面板类代码是:
public class DoubleBufferPanel : Panel
{
public DoubleBufferPanel()
{
// Set the value of the double-buffering style bits to true.
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
}
}这是一张我试图在没有任何闪烁的情况下实现的目标的图片。(没有被鼠标移动的pictureBoxes正在被绘制到面板上)。我做这件事时不能不看到闪光

发布于 2012-09-27 08:22:00
它之所以滞后,是因为您调用了Invalidate而不是Refresh。试着在表单上设置双缓冲。如果没有帮助,请阅读一些关于自定义控件的教程。链接
https://stackoverflow.com/questions/12334941
复制相似问题