Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Windows Forms
 How to: Manually Manage Buffered Gr...
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Windows Forms Programming 
How to: Manually Manage Buffered Graphics 

For more advanced double buffering scenarios, you can use the .NET Framework classes to implement your own double-buffering logic. The class responsible for allocating and managing individual graphics buffers is the BufferedGraphicsContext class. Every application has its own default BufferedGraphicsContext that manages all of the default double buffering for that application. You can retrieve a reference to this instance by calling the Current.

To obtain a reference to the default BufferedGraphicsContext

  • Set the Current property, as shown in the following code example.

    Visual Basic
    Dim myContext As BufferedGraphicsContext
    myContext = BufferedGraphicsManager.Current
    
    C#
    BufferedGraphicsContext myContext;
    myContext = BufferedGraphicsManager.Current;
    NoteNote

    You do not need to call the Dispose method on the BufferedGraphicsContext reference that you receive from the BufferedGraphicsManager class. The BufferedGraphicsManager handles all of the memory allocation and distribution for default BufferedGraphicsContext instances.

    For graphically intensive applications such as animation, you can sometimes improve performance by using a dedicated BufferedGraphicsContext instead of the BufferedGraphicsContext provided by the 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 BufferedGraphicsContext class, as shown in the following code example.

    Visual Basic
    Dim myContext As BufferedGraphicsContext
    myContext = New BufferedGraphicsContext
    ' Insert code to create graphics here.
    ' On a nondefault BufferedGraphicsContext instance, you should always 
    ' call Dispose when finished.
    myContext.Dispose()
    
    C#
    BufferedGraphicsContext myContext;
    myContext = new BufferedGraphicsContext();
    // Insert code to create graphics here.
    // On a non-default BufferedGraphicsContext instance, you should always 
    // call Dispose when finished.
    myContext.Dispose();

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker