我有一个 PictureBox 图像,它随着面板上的鼠标移动而移动。
它按照我的意愿移动,但它一直在闪烁(如刷新),我了解到这是表单的问题。
我在表单的构造函数中尝试了以下代码行,但没有成功:
SetStyle( ControlStyles.ResizeRedraw, true );
SetStyle( ControlStyles.UserPaint, true );
SetStyle( ControlStyles.AllPaintingInWmPaint, true );
SetStyle( ControlStyles.OptimizedDoubleBuffer, true );
如果有助于查看所有图片,这是鼠标移动的事件处理程序。chipHolder 是一个面板,image 是分别从文件中导入的图像。
private void grid_MouseMove(object sender, MouseEventArgs e)
{
columnPosition = e.X;
if (columnPosition != -1)
{
if (!(columnPosition < 35 || columnPosition > 610))
{
chipHolder.Controls.Clear();
PictureBox picBox = new PictureBox();
chipHolder.Controls.Add(picBox);
picBox.Image = image;
picBox.Width = image.Width;
picBox.Height = image.Height;
picBox.Location = new Point(columnPosition - 33, 0);
picBox.Show();
}
}
chipHolder.Update();
}
有任何想法吗?