HOW TO:減少使用表單和控制項的雙重緩衝的圖形重繪閃動How to: Reduce Graphics Flicker with Double Buffering for Forms and Controls

雙重緩衝會使用記憶體緩衝區來解決多個與繪製作業建立關聯的閃爍問題。Double buffering uses a memory buffer to address the flicker problems associated with multiple paint operations. 啟用雙重緩衝時,會將所有繪製作業都轉譯到記憶體緩衝區,而不是螢幕上的繪圖介面。When double buffering is enabled, all paint operations are first rendered to a memory buffer instead of the drawing surface on the screen. 在所有繪製作業都完成之後,會直接將記憶體緩衝區複製到與其建立關聯的繪圖介面。After all paint operations are completed, the memory buffer is copied directly to the drawing surface associated with it. 因為只有一個圖形作業在螢幕上執行,可排除與複雜繪製作業相關聯的影像閃爍。對於大部分的應用程式,預設雙重緩衝提供.NET Framework.NET Framework會提供最佳的結果。Because only one graphics operation is performed on the screen, the image flickering associated with complex painting operations is eliminated.For most applications, the default double buffering provided by the .NET Framework.NET Framework will provide the best results. 標準 Windows Form 控制項是雙重緩衝的預設值。Standard Windows Forms controls are double buffered by default. 您可以啟用雙重緩衝在表單中的預設值,並撰寫兩種方式的控制項。You can enable default double buffering in your forms and authored controls in two ways. 您可以設定DoubleBuffered屬性,以true,或您可以呼叫SetStyle方法來設定OptimizedDoubleBuffer旗標設為trueYou can either set the DoubleBuffered property to true, or you can call the SetStyle method to set the OptimizedDoubleBuffer flag to true. 這兩種方法會啟用預設雙重緩衝處理您的表單或控制項,並提供無閃爍的圖形轉譯。Both methods will enable default double buffering for your form or control and provide flicker-free graphics rendering. 呼叫SetStyle建議只針對有寫入所有的轉譯程式碼的自訂控制項的方法。Calling the SetStyle method is recommended only for custom controls for which you have written all the rendering code.

針對更進階雙重緩衝案例,例如動畫或進階的記憶體管理,您可以實作您自己的雙重緩衝邏輯。For more advanced double buffering scenarios, such as animation or advanced memory management, you can implement your own double buffering logic. 如需詳細資訊,請參閱<How to:手動管理已緩衝的圖形For more information, see How to: Manually Manage Buffered Graphics.

若要減少重繪閃動To reduce flicker

-或-- or -

另請參閱See also