我遇到以下问题:我在表单中放置了一个拆分器控件(不是拆分容器)并添加了 2 个面板。分离器工作正常,但是当我移动分离器时,它开始闪烁 - 面板却没有。
我使用 Split-Container 得到了相同的结果。
我试过了,但没有效果
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
...
class XSplitter : Splitter
{
public XSplitter() : base()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
}
}
class XPanel : Panel
{
public XPanel() : base()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
}
}
我使用 Windows 8.1 和 VS 2010
感谢帮助!
最佳答案
以下是使用此控件的步骤:
- 将新类“NonFlickerSplitContainer”添加到您的 C# 应用程序。
- 将自动生成的类代码替换为如下所示的 C# 代码。
在应用程序中使用 NonFlickerSplitContainer 对象而不是 SplitContainer 对象。
public partial class NonFlickerSplitContainer : SplitContainer { public NonFlickerSplitContainer() { this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); MethodInfo objMethodInfo = typeof(Control).GetMethod("SetStyle",BindingFlags.NonPublic|BindingFlags.Instance); object[] objArgs = new object[] { ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true }; objMethodInfo.Invoke(this.Panel1, objArgs); objMethodInfo.Invoke(this.Panel2, objArgs); } }
关于C# Windows 窗体 : Splitter flickering,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19859504/