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.

    Dim myContext As BufferedGraphicsContext
    myContext = BufferedGraphicsManager.Current
    
    BufferedGraphicsContext myContext;
    myContext = BufferedGraphicsManager.Current;
    

    Note

    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.

    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()
    
    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

Tasks

How to: Manually Render Buffered Graphics

Concepts

Double Buffered Graphics

Reference

BufferedGraphicsContext