다음을 통해 공유


방법: PageSetupDialog 구성 요소를 사용하여 페이지 속성 확인

PageSetupDialog 구성 요소는 문서의 사용자에게 레이아웃, 용지 크기 및 기타 페이지 레이아웃 옵션을 표시합니다.

PrintDocument 클래스의 인스턴스를 지정해야 합니다(인쇄할 문서). 또한 사용자 컴퓨터에 로컬로 또는 네트워크를 통해 프린터가 설치되어 있어야 합니다. 부분적으로 이것이 PageSetupDialog 구성 요소가 사용자에게 표시되는 페이지 서식 지정 옵션을 결정하는 방법이기 때문입니다.

PageSetupDialog 구성 요소 작업의 중요한 측면은 PageSettings 클래스와의 상호 작용 방법입니다. PageSettings 클래스는 용지 방향, 페이지의 크기, 여백 등 페이지가 인쇄되는 방법을 수정하는 설정을 지정하는 데 사용됩니다. 이러한 각 설정은 PageSettings 클래스의 속성으로 표시됩니다. PageSetupDialog 클래스는 문서와 연결된(그리고 PageSettings 속성으로 표시되는) DefaultPageSettings 클래스의 지정된 인스턴스에 대해 이러한 속성 값을 수정합니다.

PageSetupDialog 구성 요소를 사용하여 페이지 속성을 설정하려면

  1. ShowDialog 메서드를 사용하여 대화 상자를 표시하고, 사용할 PrintDocument 를 지정합니다.

    다음 예제에는 Button 컨트롤의 Click 이벤트 처리기가 PageSetupDialog 구성 요소의 인스턴스를 엽니다. Document 속성에서 기존 문서가 지정되고, 해당 PageSettings.Color 속성은 false로 설정됩니다.

    이 예제에서는 폼에 Button 컨트롤, PrintDocument 구성 요소(이름:myDocument) 및 PageSetupDialog 구성 요소가 있다고 가정합니다.

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
       ' The print document 'myDocument' used below
       ' is merely for an example.
       'You will have to specify your own print document.
       PageSetupDialog1.Document = myDocument
       ' Sets the print document's color setting to false,
       ' so that the page will not be printed in color.
       PageSetupDialog1.Document.DefaultPageSettings.Color = False
       PageSetupDialog1.ShowDialog()
    End Sub
    
    private void button1_Click(object sender, System.EventArgs e)
    {
       // The print document 'myDocument' used below
       // is merely for an example.
       // You will have to specify your own print document.
       pageSetupDialog1.Document = myDocument;
       // Sets the print document's color setting to false,
       // so that the page will not be printed in color.
       pageSetupDialog1.Document.DefaultPageSettings.Color = false;
       pageSetupDialog1.ShowDialog();
    }
    
    private:
       System::Void button1_Click(System::Object ^  sender,
          System::EventArgs ^  e)
       {
          // The print document 'myDocument' used below
          // is merely for an example.
          // You will have to specify your own print document.
          pageSetupDialog1->Document = myDocument;
          // Sets the print document's color setting to false,
          // so that the page will not be printed in color.
          pageSetupDialog1->Document->DefaultPageSettings->Color = false;
          pageSetupDialog1->ShowDialog();
       }
    

    (Visual C# 및 Visual C++) 양식의 생성자에 다음 코드를 추가하여 이벤트 처리기를 등록합니다.

    this.button1.Click += new System.EventHandler(this.button1_Click);
    
    this->button1->Click += gcnew
       System::EventHandler(this, &Form1::button1_Click);
    

참고하십시오