| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
How to: Manually Manage Buffered Graphics |
03/30/2017 |
.net-framework |
|
article |
|
|
4c2a90ee-bbbe-4ff6-9170-1b06c195c918 |
8 |
dotnet-bot |
dotnetcontent |
wpickett |
How to: Manually Manage Buffered Graphics
For more advanced double buffering scenarios, you can use the [!INCLUDEdnprdnshort] classes to implement your own double-buffering logic. The class responsible for allocating and managing individual graphics buffers is the xref:System.Drawing.BufferedGraphicsContext class. Every application has its own default xref:System.Drawing.BufferedGraphicsContext that manages all of the default double buffering for that application. You can retrieve a reference to this instance by calling the xref:System.Drawing.BufferedGraphicsManager.Current%2A.
To obtain a reference to the default BufferedGraphicsContext
-
Set the xref:System.Drawing.BufferedGraphicsManager.Current%2A property, as shown in the following code example.
[!code-csharpSystem.Windows.Forms.LegacyBufferedGraphics#11] [!code-vbSystem.Windows.Forms.LegacyBufferedGraphics#11]
[!NOTE] You do not need to call the
Disposemethod on the xref:System.Drawing.BufferedGraphicsContext reference that you receive from the xref:System.Drawing.BufferedGraphicsManager class. The xref:System.Drawing.BufferedGraphicsManager handles all of the memory allocation and distribution for default xref:System.Drawing.BufferedGraphicsContext instances.For graphically intensive applications such as animation, you can sometimes improve performance by using a dedicated xref:System.Drawing.BufferedGraphicsContext instead of the xref:System.Drawing.BufferedGraphicsContext provided by the xref:System.Drawing.BufferedGraphicsManager. This enables you to create and manage graphics buffers individually, without incurring the performance overhead of managing all the other buffered graphics associated with your application, though the memory consumed by the application will be greater.
To create a dedicated BufferedGraphicsContext
-
Declare and create a new instance of the xref:System.Drawing.BufferedGraphicsContext class, as shown in the following code example.
[!code-csharpSystem.Windows.Forms.LegacyBufferedGraphics#12] [!code-vbSystem.Windows.Forms.LegacyBufferedGraphics#12]
See Also
xref:System.Drawing.BufferedGraphicsContext
Double Buffered Graphics
How to: Manually Render Buffered Graphics