英文:
How to remove Flicker in Winform c#
问题
有没有办法在C#的Windows表单中停止闪烁?
private void btnBFS_MouseEnter(object sender, EventArgs e)
{
infoGroupbox.Text = "广度优先搜索";
travinfo.Hide();
bfsinfo.Show();
}
private void btnBFS_MouseLeave(object sender, EventArgs e)
{
infoGroupbox.Text = "遍历";
bfsinfo.Hide();
travinfo.Show();
}
我期望有一个平滑的过渡,但当我切换到其他面板或分组框时会出现闪烁。
英文:
Is there a way to stop the flickering in Windows form c#?
private void btnBFS_MouseEnter(object sender, EventArgs e)
{
infoGroupbox.Text = "Breadth First Search";
travinfo.Hide();
bfsinfo.Show();
}
private void btnBFS_MouseLeave(object sender, EventArgs e)
{
infoGroupbox.Text = "Traversal";
bfsinfo.Hide();
travinfo.Show();
}
Im expecting smooth transition but when i transition to other panel or groupbox it flickers.
答案1
得分: 1
以下代码有助于消除闪烁。仅将DoubleBuffered属性设置为true通常是不够的。以下代码可应用于包含有问题控件的窗体或面板。
public void EnableDoubleBuffering()
{
// 将双缓冲样式位的值设置为true。
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}
在WinForms中实现平滑过渡并不容易。您需要重写控件的Paint方法并使用定时器来工作。
英文:
The following code helps to remove flickering. Just setting DoubleBuffered = true is often not enough. The following code can be applied to a form or a panel in which the problematic controls are located.
public void EnableDoubleBuffering()
{
// Set the value of the double-buffering style bits to true.
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}
Smooth transitions in WinForms are not easy to accomblisch. You need to override the Paint of a control and work with timers.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论