我在 Windows 窗体中使用以下代码来移动按钮。但是,按钮在移动时会闪烁。即使我使用的是 SmoothingMode.HighQuality 和 DoubleBuffer。
如何减少按钮的闪烁?
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
this.DoubleBuffered = true;
if (button1.Location.X > 10 && button1.Location.X < 550)
{
Point osp = new Point(button1.Location.X + 1, button1.Location.Y);
button1.Location = osp;
}
else
{
Point osp = new Point(11, button1.Location.Y);
button1.Location = osp;
}
}