【发布时间】:2013-05-02 17:46:27
【问题描述】:
我正在制作一个 Windows 窗体应用程序,主要是我的屏幕分为 3 个部分,例如
===========================================================================
Top panel (it doesn't flicker)
===========================================================================
|| || 'it has a panel & panel contains a table layout,this tabble layout'
|| || 'has a picture box and a label, picture & text of label is'
|| ||'changed on the click of side bar menu' (PROB: this flickers a lot)
||side bar ||==============================================================
||(doesn't ||'this part also has a panel and panel contains different table'
||flicker) ||'layouts and on the click of a menu, related table layout is shown and'
|| ||'some of the parts of table layout are created dynamically.'
|| ||
|| || (PROB: this flickers a lot)
|| ||
我搜索了很多,到处都找到了这个解决方案,我尝试了这个
public constructor()
{
InitializeComponent();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
DoubleBuffered = true;
SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.ContainerControl |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.SupportsTransparentBackColor
, true);
}
我也试过了
protected override CreateParams CreateParams
{
get
{
CreateParams handleParam = base.CreateParams;
handleParam.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
return handleParam;
}
}
它将我的屏幕的整个背景变为黑色。
但问题仍然存在,有人可以告诉我如何解决这个问题以及我在哪里做错了吗? 提前非常感谢。
【问题讨论】:
-
没有更新屏幕不会闪烁。所以请向我们展示重复更新闪烁部分的代码。
-
闪烁的控件类型是什么?你在用这些问题控制做什么? EG:加载 100,000 条记录以供显示等...
-
你用这个表格做什么?我的意思是:它在哪个动作上闪烁?如果您制作一个 WinForm,例如,3 个面板等区域并将一些控件放入这些面板中,它根本不应该闪烁。既不是点击面板也不是拖动窗口。
-
在您的解决方案尝试代码中:this.DoubleBuffered = true;和双缓冲=真;做同样的事情。与 SetStyle 调用相同。因为“this”显式引用了本地范围(至少在这段代码中被剪掉了)。如果你在代码的其他地方重复调用这些东西并快速设置和取消设置某些值,这也会产生闪烁。 (在 OP 添加新代码 sn-p 之后:)您仍然应该告诉我们您的 PROB 区域内发生了什么。 (这些是 userControls 吗?PictureBoxes?你是在他们的背景上绘画吗(使用 OnPaint)?)
-
我做了一些事情(但现在已经大约 4 年了......)阻止屏幕布局更新,直到我完成我的工作......我认为它类似于“SuspendLayout( )" 和 "ResumeLayout()"...你可能想看看它。