How to: Manually Render Buffered Graphics
If you are managing your own buffered graphics, you will need to be able to create and render graphics buffers. You can create instances of the BufferedGraphics class that is associated with drawing surfaces on your screen by calling the Allocate. This method creates a BufferedGraphics instance that is associated with a particular rendering surface, such as a form or control. After you have created a BufferedGraphics instance, you can draw graphics to the buffer it represents through the Graphics property. After you have performed all graphics operations, you can copy the contents of the buffer to the screen by calling the Render method.
If you perform your own rendering, memory consumption will increase, though the increase may only be slight.
To manually display buffered graphics
// This example assumes the existence of a form called Form1. BufferedGraphicsContext currentContext; BufferedGraphics myBuffer; // Gets a reference to the current BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; // Creates a BufferedGraphics instance associated with Form1, and with // dimensions the same size as the drawing surface of Form1. myBuffer = currentContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);
Draw graphics to the graphics buffer by setting the Graphics property. For example:
When you have completed all of your drawing operations to the graphics buffer, call the Render method to render the buffer, either to the drawing surface associated with that buffer, or to a specified drawing surface, as shown in the following code example.
// This example assumes the existence of a BufferedGraphics instance // called myBuffer. // Renders the contents of the buffer to the drawing surface associated // with the buffer. myBuffer.Render(); // Renders the contents of the buffer to the specified drawing surface. myBuffer.Render(this.CreateGraphics());
After you are finished rendering graphics, call the Dispose method on the BufferedGraphics instance to free system resources.