Graphics.EndContainer メソッド
アセンブリ: System.Drawing (system.drawing.dll 内)


入れ子のグラフィックス コンテナを作成するには、このメソッドと共に BeginContainer メソッドを使用します。グラフィックス コンテナは、変換、クリッピング領域、レンダリング プロパティなど、グラフィックスの状態を保持します。
Graphics の BeginContainer メソッドを呼び出すと、Graphics の状態を保持している情報ブロックがスタックに格納されます。BeginContainer メソッドは、その情報ブロックを識別する GraphicsContainer を返します。識別対象のオブジェクトを EndContainer メソッドに渡すと、情報ブロックはスタックから削除され、Graphics を BeginContainer メソッド呼び出し時の状態に復元するために使用されます。
コンテナは入れ子にできます。つまり、EndContainer メソッドを呼び出す前に、BeginContainer メソッドを複数回呼び出すことができます。BeginContainer メソッドを呼び出すたびに、情報ブロックがスタックに格納され、その情報ブロックの GraphicsContainer を受け取ります。これらのオブジェクトの 1 つを EndContainer メソッドに渡すと、Graphics は、その GraphicsContainer を返した BeginContainer メソッドの呼び出し時の状態に戻ります。その BeginContainer メソッドの呼び出しによってスタックに置かれた情報ブロックはスタックから削除されます。さらに、BeginContainer メソッドの呼び出し後にスタックに置かれたすべての情報ブロックも削除されます。
Save メソッドの呼び出しは、BeginContainer メソッドの呼び出しと同じスタックに情報ブロックを配置します。EndContainer メソッド呼び出しが BeginContainer メソッド呼び出しと対になっているのと同様に、Restore メソッド呼び出しは Save メソッド呼び出しと対になっています。
EndContainer メソッドを呼び出すと、対応する BeginContainer メソッドの呼び出し後に (Save メソッドまたは BeginContainer メソッドによって) スタックに格納されたすべての情報ブロックが、スタックから削除されます。同様に、Restore メソッドを呼び出すと、対応する BeginContainer メソッドの呼び出し後に (Save メソッドまたは Save メソッドによって) スタックに格納されたすべての情報ブロックが、スタックから削除されます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
Public Sub EndContainerState(ByVal e As PaintEventArgs) ' Begin graphics container. Dim containerState As GraphicsContainer = _ e.Graphics.BeginContainer() ' Translate world transformation. e.Graphics.TranslateTransform(100.0F, 100.0F) ' Fill translated rectangle in container with red. e.Graphics.FillRectangle(New SolidBrush(Color.Red), 0, 0, _ 200, 200) ' End graphics container. e.Graphics.EndContainer(containerState) ' Fill untransformed rectangle with green. e.Graphics.FillRectangle(New SolidBrush(Color.Green), 0, 0, _ 200, 200) End Sub
public void EndContainerState(PaintEventArgs e) { // Begin graphics container. GraphicsContainer containerState = e.Graphics.BeginContainer(); // Translate world transformation. e.Graphics.TranslateTransform(100.0F, 100.0F); // Fill translated rectangle in container with red. e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200); // End graphics container. e.Graphics.EndContainer(containerState); // Fill untransformed rectangle with green. e.Graphics.FillRectangle(new SolidBrush(Color.Green), 0, 0, 200, 200); }
public: void EndContainerState( PaintEventArgs^ e ) { // Begin graphics container. GraphicsContainer^ containerState = e->Graphics->BeginContainer(); // Translate world transformation. e->Graphics->TranslateTransform( 100.0F, 100.0F ); // Fill translated rectangle in container with red. e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), 0, 0, 200, 200 ); // End graphics container. e->Graphics->EndContainer( containerState ); // Fill untransformed rectangle with green. e->Graphics->FillRectangle( gcnew SolidBrush( Color::Green ), 0, 0, 200, 200 ); }
public void EndContainerState(PaintEventArgs e) { // Begin graphics container. GraphicsContainer containerState = e.get_Graphics().BeginContainer(); // Translate world transformation. e.get_Graphics().TranslateTransform(100, 100); // Fill translated rectangle in container with red. e.get_Graphics().FillRectangle(new SolidBrush(Color.get_Red()), 0, 0, 200, 200); // End graphics container. e.get_Graphics().EndContainer(containerState); // Fill untransformed rectangle with green. e.get_Graphics().FillRectangle(new SolidBrush(Color.get_Green()), 0, 0, 200, 200); } //EndContainerState

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGraphics.EndContainer メソッドを検索する場合は、下記のリンクをクリックしてください。

- Graphics.EndContainer メソッドのページへのリンク