PageSetupDialog 구성 요소를 사용하면 문서의 레이아웃, 용지 크기 및 기타 페이지 레이아웃과 관련된 옵션을 선택할 수 있습니다.
PrintDocument 클래스의 인스턴스 즉, 인쇄할 문서를 지정해야 합니다. 또한 사용자의 컴퓨터에 로컬로 또는 네트워크를 통해 프린터가 설치되어 있어야 합니다. 프린터는 PageSetupDialog 구성 요소가 사용자에게 제공할 페이지 서식 옵션을 결정하는 데 영향을 줍니다.
PageSetupDialog 구성 요소를 사용할 경우에는 이 구성 요소가 PageSettings 클래스와 상호 작용하는 방식이 중요합니다. PageSettings 클래스는 용지 방향, 페이지 크기, 여백 등 페이지 인쇄 방법을 수정하는 설정을 지정하는 데 사용됩니다. 이러한 각 설정은 PageSettings 클래스의 속성으로 표시됩니다. PageSetupDialog 클래스는 문서와 연결되어 있고 DefaultPageSettings 속성으로 표시되는 PageSettings 클래스의 특정 인스턴스에 대해 이러한 속성 값을 수정합니다.
PageSetupDialog 구성 요소를 사용하여 페이지 속성을 설정하려면
ShowDialog 메서드를 사용하여 대화 상자를 표시하고 사용할 PrintDocument를 지정합니다.
아래 예제에서는 Button 컨트롤의 Click 이벤트 처리기를 사용하여 PageSetupDialog 구성 요소의 인스턴스를 엽니다. Document 속성에 기존 문서가 지정되어 있고 PageSettings.Color 속성은 false로 설정되어 있습니다.
이 예제에서는 폼에 Button 컨트롤, 이름이 myDocument인 PrintDocument 구성 요소 및 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);
참고 항목
작업
방법: 표준 Windows Forms 인쇄 작업 만들기