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

GraphicsState가 복원될 상태를 나타내는 Graphics입니다.

예제

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

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

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

  • 폼의 월드 변환을 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

설명

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

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

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

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

적용 대상