我有一个表单,其中加载了一个用户控件,其中包含 3 个其他用户控件。
每次我移动到另一个选项卡并返回到该用户控件时,其中的 3 个控件甚至在事件触发之前就会闪烁。
我尝试了一切,包括:
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
and
protected override CreateParams CreateParams
{
get
{
CreateParams baseParams = base.CreateParams;
baseParams.ExStyle |= 0x0200000;
return baseParams;
}
}
and
protected override CreateParams CreateParams
{
get
{
CreateParams baseParams = base.CreateParams;
baseParams.ExStyle &= 0x0200000;
return baseParams;
}
}
但没有任何帮助。闪烁发生在任何代码运行之前。
可能是什么问题?
发生这种情况可能是因为每次都会绘制背景。
If all你的画是在OnPaint()
(包括清除背景 - 您的嵌套用户控件可能正在自行执行此操作,因此应该没问题),然后您可以完全禁用背景绘制,如下所示:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// Do nothing to disable background painting.
}
您可能会发现在一个或多个嵌套用户控件的实现中也需要执行此操作。
另外,如果您正在自定义现有的 Windows 控件以防止其闪烁,有时您必须执行以下操作(但这不是您应该为用户控件之一执行的操作):
private const int WM_ERASEBKGND = 20;
[PermissionSet(SecurityAction.Demand, Unrestricted=true)]
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_ERASEBKGND)
{
m.Result = IntPtr.Zero;
}
else
{
base.WndProc(ref m);
}
}
我在定制时必须这样做ListView
以防止其闪烁。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)