Graphics.EndContainer メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Graphics.EndContainer メソッドの意味・解説 

Graphics.EndContainer メソッド

現在のグラフィックス コンテナを閉じ、この Graphics の状態を、BeginContainer メソッドを呼び出すことによって保存されていた状態に復元します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub EndContainer ( _
    container As GraphicsContainer _
)
Dim instance As Graphics
Dim container As GraphicsContainer

instance.EndContainer(container)
public void EndContainer (
    GraphicsContainer container
)
public:
void EndContainer (
    GraphicsContainer^ container
)
public void EndContainer (
    GraphicsContainer container
)
public function EndContainer (
    container : GraphicsContainer
)

パラメータ

container

このメソッドで復元されるコンテナを表す GraphicsContainer。

解説解説

入れ子のグラフィックス コンテナを作成するには、このメソッドと共に 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Graphics.EndContainer メソッド」の関連用語

Graphics.EndContainer メソッドのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



Graphics.EndContainer メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS