C# Windows 窗体 : Splitter flickering

标签 c# winforms splitter

我遇到以下问题:我在表单中放置了一个拆分器控件(不是拆分容器)并添加了 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/

相关文章:

c# - 是否可以强制显式实现接口(interface)(或接口(interface)的一部分)?

c# - DPI 图形屏幕分辨率像素 WinForm PrintPageEventArgs

c# - 生成颜色渐变

java - Camel split xml 保留一些节点

c# - 在 LINQ 中返回 null 而不是默认值

c# - 从另一个表达式构建索引表达式

c# - 如何为 DataRepeater 链接标签设置唯一 ID

java - Spring 集成: Pass Entire List of object from router to service at one time

delphi - 使用拆分器时如何保持控件在表单中可见?

c# - 在 asp.net 发布后为空?编辑模型