バッファリングされたグラフィックスを独自に管理する場合は、グラフィックス バッファーを作成して描画できるようにする必要があります。 Allocate を呼び出すと、画面上の描画サーフェイスに関連付けられた BufferedGraphics クラスのインスタンスを作成できます。 このメソッドは、フォームやコントロールなどの特定の描画面に関連付けられた BufferedGraphics を作成します。 BufferedGraphics インスタンスを作成したら、Graphics プロパティを介してこのインスタンスが表すバッファーにグラフィックスを描画できます。 グラフィックス操作をすべて完了したら、Render メソッドを呼び出して、バッファーの内容を画面にコピーできます。
注意
独自の描画を実行した場合は、ごくわずかですがメモリの使用量が増大します。
バッファリングされたグラフィックスを手動で表示するには
BufferedGraphicsContext クラスのインスタンスへの参照を取得します。 詳細については、「方法 : バッファリングされたグラフィックスを手動で管理する」を参照してください。
次のコード例に示すように、Allocate メソッドを呼び出して BufferedGraphics クラスのインスタンスを作成します。
' 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)
// 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);
Graphics プロパティを設定して、グラフィックスをグラフィックス バッファーに描画します。 この例を次に示します。
' Draws an ellipse to the graphics buffer. myBuffer.Graphics.DrawEllipse(Pens.Blue, Me.DisplayRectangle)
// Draws an ellipse to the graphics buffer. myBuffer.Graphics.DrawEllipse(Pens.Blue, this.DisplayRectangle);
グラフィックス バッファーへの描画操作をすべて完了したら、Render メソッドを呼び出して、このバッファーに関連付けられた描画サーフェイスまたは指定した描画サーフェイスにバッファーを描画します。この例を次に示します。
' 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)
// 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());
グラフィックスの描画を終了したら、BufferedGraphics インスタンスの Dispose メソッドを呼び出してシステム リソースを解放します。
myBuffer.Dispose()
myBuffer.Dispose();
参照
処理手順
方法 : バッファリングされたグラフィックスを手動で管理する