Graphics.EndContainer(GraphicsContainer) 메서드

정의

현재 그래픽 컨테이너를 닫고 Graphics 메서드에 대한 호출에 의해 저장된 상태로 이 BeginContainer()의 상태를 복원합니다.

public:
 void EndContainer(System::Drawing::Drawing2D::GraphicsContainer ^ container);
public void EndContainer (System.Drawing.Drawing2D.GraphicsContainer container);
member this.EndContainer : System.Drawing.Drawing2D.GraphicsContainer -> unit
Public Sub EndContainer (container As GraphicsContainer)

매개 변수

container
GraphicsContainer

이 메서드가 복원하는 컨테이너를 나타내는 GraphicsContainer입니다.

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse 코드는 다음 작업을 수행합니다.

  • 새 그래픽 컨테이너를 열고 이전 컨테이너를 저장합니다.

  • 컨테이너의 월드 좌표를 변환합니다.

  • 새 컨테이너의 (변환된 좌표)에 빨간색 사각형을 채웁니다.

  • 새 컨테이너를 닫고 저장된 컨테이너를 복원합니다.

  • 저장된 컨테이너의 녹색 사각형(변환되지 않은 좌표)을 채웁니다.

그 결과 동일한 크기의 빨간색 사각형 위에 있는 녹색 사각형이 생성됩니다.

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.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 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

설명

메서드와 함께 이 메서드를 BeginContainer 사용하여 중첩된 그래픽 컨테이너를 만듭니다. 그래픽 컨테이너는 변환, 클리핑 영역 및 렌더링 속성과 같은 그래픽 상태를 유지합니다.

의 메서드를 BeginContainerGraphics호출하면 의 Graphics 상태를 보유하는 정보 블록이 스택에 배치됩니다. 메서드는 BeginContainer 해당 정보 블록을 식별하는 를 반환 GraphicsContainer 합니다. 식별 개체를 메서드에 EndContainer 전달하면 정보 블록이 스택에서 제거되고 메서드 호출 당시 BeginContainer 의 상태로 를 복원 Graphics 하는 데 사용됩니다.

컨테이너를 중첩할 수 있습니다. 즉, 메서드를 호출하기 전에 메서드를 BeginContainer 여러 번 호출할 EndContainer 수 있습니다. 메서드를 BeginContainer 호출할 때마다 정보 블록이 스택에 배치되고 정보 블록에 대한 를 GraphicsContainer 받습니다. 이러한 개체 중 하나를 메서드 GraphicsEndContainer 전달하면 는 특정 GraphicsContainer를 반환한 메서드 호출 당시의 BeginContainer 상태로 반환됩니다. 해당 BeginContainer 메서드 호출에 의해 스택에 배치된 정보 블록은 스택에서 제거되고 해당 메서드 호출 후에 BeginContainer 해당 스택에 배치된 모든 정보 블록도 제거됩니다.

메서드에 대한 호출은 Save 메서드에 대한 호출 BeginContainer 과 동일한 스택에 정보 블록을 배치합니다. EndContainer 메서드 호출이 메서드 호출 Restore 과 쌍을 BeginContainer 이루는 것처럼 메서드 호출은 메서드 호출과 쌍을 이 Save 릅니다.

메서드를 EndContainer 호출하면 메서드에 대한 해당 호출 BeginContainer 후 스택에 배치된 모든 정보 블록(Save메서드 또는 BeginContainer 메서드)이 스택에서 제거됩니다. 마찬가지로 메서드를 Restore 호출할 때 메서드에 대한 해당 호출 Save 후 스택에 배치된 모든 정보 블록(Save메서드 또는 BeginContainer 메서드)이 스택에서 제거됩니다.

적용 대상