2008-11-19 91 views
1

我已經看到下面的代碼在一個winform啓用雙緩衝:啓用雙緩衝

// Activates double buffering 
this.SetStyle(ControlStyles.DoubleBuffer | 
    ControlStyles.OptimizedDoubleBuffer | 
    ControlStyles.UserPaint | 
    ControlStyles.AllPaintingInWmPaint, true); 
this.UpdateStyles(); 

以任何方式這不同於簡單地設置Form.DoubleBuffering =真的嗎?

回答

5

Control.DoubleBuffering執行

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

因此您的代碼設置樣式同樣設置了ControlStyles.UserPaint(這可能對此沒有影響)。

2

設置窗體的DoubleBuffering將爲該窗體設置雙緩衝。這是與調用

form.SetStyle(ControlStyles.OptimizedDoubleBuffer, value); 

其他標誌一樣UserPaint和AllPaintingInWmPaint是不是通過簡單地設置control.DoubleBuffering =真

1

.NET 1. x,控件上沒有DoubleBuffered屬性,所以SetStyle是啓用它的唯一方法。您看到使用SetStyle的代碼可能仍然在1. x天左右,或者從那時起只是沒有改變習慣的開發者。

1

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); 
}