Enabling Double Buffering

后端 未结 4 990
抹茶落季
抹茶落季 2020-12-22 04:35

I\'ve seen the following code to enable double buffering on a winform:

// Activates double buffering 
this.SetStyle(ControlStyles.DoubleBuffer |
   ControlSt         


        
相关标签:
4条回答
  • 2020-12-22 04:47

    From Stackoverflow: How to double buffer .NET controls on a form?:

    public static void SetDoubleBuffered(System.Windows.Forms.Control c)
    {
       //Taxes: Remote Desktop Connection and painting
       //http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx
       if (System.Windows.Forms.SystemInformation.TerminalServerSession)
          return;
    
       System.Reflection.PropertyInfo aProp = typeof(System.Windows.Forms.Control).GetProperty(
            "DoubleBuffered",
             System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
       aProp.SetValue(c, true, null); 
    }
    
    0 讨论(0)
  • 2020-12-22 04:54

    Setting a form's DoubleBuffering will set double buffering for that form. It's the same as calling

    form.SetStyle(ControlStyles.OptimizedDoubleBuffer, value);
    

    The other flags like UserPaint and AllPaintingInWmPaint are styles that aren't set by simply setting control.DoubleBuffering = true

    0 讨论(0)
  • 2020-12-22 04:58

    In .NET 1.x, there was no DoubleBuffered property on controls, so SetStyle was the only way to enable it. Code your see that uses SetStyle is probably either still around from 1.x days, or from developers who just haven't changed their habits since then.

    0 讨论(0)
  • 2020-12-22 04:59

    Control.DoubleBuffering performs

    SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, value);
    

    so your code sets ControlStyles.UserPaint as well (which probably has no effect at this point).

    0 讨论(0)
提交回复
热议问题