# HOW TO：手動呈現已緩衝的圖形How to: Manually Render Buffered Graphics

### 手動顯示已緩衝的圖形To manually display buffered graphics

1. 取得 BufferedGraphicsContext 類別執行個體的參考。Obtain a reference to an instance of the BufferedGraphicsContext class. 如需詳細資訊，請參閱如何：手動管理已緩衝的圖形For more information, see How to: Manually Manage Buffered Graphics.

2. 藉由呼叫 Allocate 方法，建立 BufferedGraphics 類別的執行個體，如下列程式碼範例所示。Create an instance of the BufferedGraphics class by calling the Allocate method, as shown in the following code example.

// 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);

' This example assumes the existence of a form called Form1.
Dim currentContext As BufferedGraphicsContext
Dim myBuffer As BufferedGraphics
' 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(Me.CreateGraphics, _
Me.DisplayRectangle)


3. 藉由設定 Graphics 屬性，繪製圖形至圖形緩衝區。Draw graphics to the graphics buffer by setting the Graphics property. 例如：For example:

// Draws an ellipse to the graphics buffer.
myBuffer.Graphics.DrawEllipse(Pens.Blue, this.DisplayRectangle);

' Draws an ellipse to the graphics buffer.
myBuffer.Graphics.DrawEllipse(Pens.Blue, Me.DisplayRectangle)

4. 當您完成對圖形緩衝區的所有繪圖作業時，請呼叫 Render 方法以轉譯緩衝區，不論是轉譯到與該緩衝區關聯的繪圖介面，或是指定的繪圖介面，如下列程式碼範例所示。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());

' 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(Me.CreateGraphics)

5. 完成轉譯圖形之後，請對 BufferedGraphics 執行個體呼叫 Dispose 方法以釋放系統資源。After you are finished rendering graphics, call the Dispose method on the BufferedGraphics instance to free system resources.

myBuffer.Dispose();

myBuffer.Dispose()