다음을 통해 공유


Graphics.Restore(GraphicsState) 메서드

정의

Graphics 상태를 GraphicsState나타내는 상태로 복원합니다.

public:
 void Restore(System::Drawing::Drawing2D::GraphicsState ^ gstate);
public void Restore (System.Drawing.Drawing2D.GraphicsState gstate);
member this.Restore : System.Drawing.Drawing2D.GraphicsState -> unit
Public Sub Restore (gstate As GraphicsState)

매개 변수

gstate
GraphicsState

Graphics복원할 상태를 나타내는 GraphicsState.

예제

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

  • 벡터(100, 0)로 Windows Form의 월드 변환을 변환합니다.

  • 폼의 그래픽 상태를 저장합니다.

  • 폼의 월드 변환을 ID로 재설정하고 사각형을 단색 빨간색 브러시로 채웁니다.

  • 변환된 그래픽 상태를 복원하고 두 번째 사각형을 단색 파란색 브러시로 채웁니다.

그 결과 변환되지 않은 빨간색으로 채워진 사각형과 변환된 파란색으로 채워진 사각형이 생성됩니다.

public:
   void SaveRestore2( PaintEventArgs^ e )
   {
      // Translate transformation matrix.
      e->Graphics->TranslateTransform( 100, 0 );

      // Save translated graphics state.
      GraphicsState^ transState = e->Graphics->Save();

      // Reset transformation matrix to identity and fill rectangle.
      e->Graphics->ResetTransform();
      e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), 0, 0, 100, 100 );

      // Restore graphics state to translated state and fill second
      // rectangle.
      e->Graphics->Restore( transState );
      e->Graphics->FillRectangle( gcnew SolidBrush( Color::Blue ), 0, 0, 100, 100 );
   }
private void SaveRestore2(PaintEventArgs e)
{

    // Translate transformation matrix.
    e.Graphics.TranslateTransform(100, 0);

    // Save translated graphics state.
    GraphicsState transState = e.Graphics.Save();

    // Reset transformation matrix to identity and fill rectangle.
    e.Graphics.ResetTransform();
    e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 100, 100);

    // Restore graphics state to translated state and fill second

    // rectangle.
    e.Graphics.Restore(transState);
    e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 100, 100);
}
Private Sub SaveRestore2(ByVal e As PaintEventArgs)

    ' Translate transformation matrix.
    e.Graphics.TranslateTransform(100, 0)

    ' Save translated graphics state.
    Dim transState As GraphicsState = e.Graphics.Save()

    ' Reset transformation matrix to identity and fill rectangle.
    e.Graphics.ResetTransform()
    e.Graphics.FillRectangle(New SolidBrush(Color.Red), 0, 0, 100, 100)

    ' Restore graphics state to translated state and fill second

    ' rectangle.
    e.Graphics.Restore(transState)
    e.Graphics.FillRectangle(New SolidBrush(Color.Blue), 0, 0, _
    100, 100)
End Sub

설명

Graphics Save 메서드를 호출하면 Graphics 상태를 보유하는 정보 블록이 스택에 배치됩니다. Save 메서드는 해당 정보 블록을 식별하는 GraphicsState 반환합니다. 식별 GraphicsStateRestore 메서드에 전달하면 정보 블록이 스택에서 제거되고 Save 메서드 호출 당시의 상태로 Graphics 복원하는 데 사용됩니다. Save 메서드에 대한 지정된 호출에서 반환된 GraphicsStateRestore 메서드에 한 번만 전달할 수 있습니다.

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

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

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

적용 대상