다음을 통해 공유


PrintDialog 클래스

정의

사용자가 프린터를 선택하고 Windows Forms 애플리케이션에서 인쇄할 문서의 섹션을 선택할 수 있습니다.

public ref class PrintDialog sealed : System::Windows::Forms::CommonDialog
public sealed class PrintDialog : System.Windows.Forms.CommonDialog
type PrintDialog = class
    inherit CommonDialog
Public NotInheritable Class PrintDialog
Inherits CommonDialog
상속

예제

다음 코드 예제에서는 컨트롤을 사용 하 여 PrintDialog 설정 하는 방법을 보여 줍니다. ShowHelpAllowSomePagesDocument 이 예제를 실행하려면 다음 코드를 명명된 컨트롤과 이름이 PrintDialog1 지정된 Button1단추가 포함된 PrintDialog 폼에 붙여넣습니다. 이 예제에서는 단추의 Click 이벤트와 PrintPage 이벤트가 docToPrint 이 예제에 정의된 이벤트 처리 메서드에 연결되어야 합니다.

// Declare the PrintDocument object.
System::Drawing::Printing::PrintDocument^ docToPrint;

// This method will set properties on the PrintDialog object and
// then display the dialog.
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   // Allow the user to choose the page range he or she would
   // like to print.
   PrintDialog1->AllowSomePages = true;
   
   // Show the help button.
   PrintDialog1->ShowHelp = true;
   
   // Set the Document property to the PrintDocument for 
   // which the PrintPage Event has been handled. To display the
   // dialog, either this property or the PrinterSettings property 
   // must be set 
   PrintDialog1->Document = docToPrint;
   if ( docToPrint == nullptr )
         System::Windows::Forms::MessageBox::Show(  "null" );

   ;
   ;
   if ( PrintDialog1 == nullptr )
         System::Windows::Forms::MessageBox::Show(  "pnull" );

   ;
   ;
   System::Windows::Forms::DialogResult result = PrintDialog1->ShowDialog();
   System::Windows::Forms::MessageBox::Show( result.ToString() );
   ;
   ;
   
   // If the result is OK then print the document.
   if ( result == ::DialogResult::OK )
   {
      docToPrint->Print();
   }

}

// The PrintDialog will print the document
// by handling the document's PrintPage event.
void document_PrintPage( Object^ /*sender*/, System::Drawing::Printing::PrintPageEventArgs^ e )
{
   // Insert code to render the page here.
   // This code will be called when the control is drawn.
   // The following code will render a simple
   // message on the printed document.
   String^ text = "In document_PrintPage method.";
   System::Drawing::Font^ printFont = gcnew System::Drawing::Font( "Arial",35,System::Drawing::FontStyle::Regular );
   
   // Draw the content.
   e->Graphics->DrawString( text, printFont, System::Drawing::Brushes::Black, 10, 10 );
}

// Declare the PrintDocument object.
private System.Drawing.Printing.PrintDocument docToPrint = 
    new System.Drawing.Printing.PrintDocument();

// This method will set properties on the PrintDialog object and
// then display the dialog.
private void Button1_Click(System.Object sender, 
    System.EventArgs e)
{

    // Allow the user to choose the page range he or she would
    // like to print.
    PrintDialog1.AllowSomePages = true;

    // Show the help button.
    PrintDialog1.ShowHelp = true;

    // Set the Document property to the PrintDocument for 
    // which the PrintPage Event has been handled. To display the
    // dialog, either this property or the PrinterSettings property 
    // must be set 
    PrintDialog1.Document = docToPrint;

    DialogResult result = PrintDialog1.ShowDialog();

    // If the result is OK then print the document.
    if (result==DialogResult.OK)
    {
        docToPrint.Print();
    }
}

// The PrintDialog will print the document
// by handling the document's PrintPage event.
private void document_PrintPage(object sender, 
    System.Drawing.Printing.PrintPageEventArgs e)
{

    // Insert code to render the page here.
    // This code will be called when the control is drawn.

    // The following code will render a simple
    // message on the printed document.
    string text = "In document_PrintPage method.";
    System.Drawing.Font printFont = new System.Drawing.Font
        ("Arial", 35, System.Drawing.FontStyle.Regular);

    // Draw the content.
    e.Graphics.DrawString(text, printFont, 
        System.Drawing.Brushes.Black, 10, 10);
}

' Declare the PrintDocument object.
Private WithEvents docToPrint As New Printing.PrintDocument

' This method will set properties on the PrintDialog object and
' then display the dialog.
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' Allow the user to choose the page range he or she would
    ' like to print.
    PrintDialog1.AllowSomePages = True

    ' Show the help button.
    PrintDialog1.ShowHelp = True

    ' Set the Document property to the PrintDocument for 
    ' which the PrintPage Event has been handled. To display the
    ' dialog, either this property or the PrinterSettings property 
    ' must be set 
    PrintDialog1.Document = docToPrint

    Dim result As DialogResult = PrintDialog1.ShowDialog()

    ' If the result is OK then print the document.
    If (result = DialogResult.OK) Then
        docToPrint.Print()
    End If

End Sub

' The PrintDialog will print the document
' by handling the document's PrintPage event.
Private Sub document_PrintPage(ByVal sender As Object, _
   ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
       Handles docToPrint.PrintPage

    ' Insert code to render the page here.
    ' This code will be called when the control is drawn.

    ' The following code will render a simple
    ' message on the printed document.
    Dim text As String = "In document_PrintPage method."
    Dim printFont As New System.Drawing.Font _
        ("Arial", 35, System.Drawing.FontStyle.Regular)

    ' Draw the content.
    e.Graphics.DrawString(text, printFont, _
        System.Drawing.Brushes.Black, 10, 10)
End Sub

설명

인스턴스 PrintDialog를 만들면 읽기/쓰기 속성이 초기 값으로 설정됩니다. 이러한 값의 목록은 PrintDialog 생성자를 참조하세요. 사용자가 PrintDialog수정한 프린터 설정을 사용하려면 속성을 사용합니다 PrinterSettings .

Windows Forms를 사용하여 인쇄하는 방법에 대한 자세한 내용은 네임스페이스 개요를 System.Drawing.Printing 참조하세요. Windows Presentation Foundation 애플리케이션에서 인쇄하려면 네임스페이스를 System.Printing 참조하세요.

생성자

Name Description
PrintDialog()

PrintDialog 클래스의 새 인스턴스를 초기화합니다.

속성

Name Description
AllowCurrentPage

현재 페이지 옵션 단추가 표시되는지 여부를 나타내는 값을 가져오거나 설정합니다.

AllowPrintToFile

파일로 인쇄 확인란을 사용할 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

AllowSelection

선택 옵션 단추가 사용되는지 여부를 나타내는 값을 가져오거나 설정합니다.

AllowSomePages

페이지 옵션 단추가 사용되는지 여부를 나타내는 값을 가져오거나 설정합니다.

CanRaiseEvents

구성 요소가 이벤트를 발생시키는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
Container

IContainer 포함하는 값을 가져옵니다 Component.

(다음에서 상속됨 Component)
DesignMode

현재 디자인 모드인지 여부를 Component 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
Document

가져오는 PrinterSettings데 사용되는 값을 PrintDocument 가져오거나 설정합니다.

Events

Component에 연결된 이벤트 처리기 목록을 가져옵니다.

(다음에서 상속됨 Component)
PrinterSettings

대화 상자가 수정하는 프린터 설정을 가져오거나 설정합니다.

PrintToFile

파일로 인쇄 확인란이 선택되어 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

ShowHelp

도움말 단추가 표시되는지 여부를 나타내는 값을 가져오거나 설정합니다.

ShowNetwork

네트워크 단추가 표시되는지 여부를 나타내는 값을 가져오거나 설정합니다.

Site

ISite값을 Component 가져오거나 설정합니다.

(다음에서 상속됨 Component)
Tag

컨트롤에 대한 데이터가 포함된 개체를 가져오거나 설정합니다.

(다음에서 상속됨 CommonDialog)
UseEXDialog

Windows XP Home Edition, Windows XP Professional, Windows Server 2003 이상을 실행하는 시스템의 경우 대화 상자를 Windows XP 스타일로 표시할지 여부를 나타내는 값을 가져오거나 설정합니다.

메서드

Name Description
CreateObjRef(Type)

원격 개체와 통신하는 데 사용되는 프록시를 생성하는 데 필요한 모든 관련 정보를 포함하는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Dispose()

에서 사용하는 모든 리소스를 Component해제합니다.

(다음에서 상속됨 Component)
Dispose(Boolean)

관리되지 않는 리소스를 Component 해제하고 관리되는 리소스를 선택적으로 해제합니다.

(다음에서 상속됨 Component)
Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 현재 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetService(Type)

또는 해당 서비스에서 제공하는 서비스를 나타내는 개체를 Component 반환합니다 Container.

(다음에서 상속됨 Component)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

공통 대화 상자에 특정 기능을 추가하도록 재정의되는 일반적인 대화 상자 후크 프로시저를 정의합니다.

(다음에서 상속됨 CommonDialog)
InitializeLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.

(다음에서 상속됨 MarshalByRefObject)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
MemberwiseClone(Boolean)

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
OnHelpRequest(EventArgs)

HelpRequest 이벤트를 발생시킵니다.

(다음에서 상속됨 CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

공통 대화 상자에 특정 기능을 추가하도록 재정의되는 소유자 창 프로시저를 정의합니다.

(다음에서 상속됨 CommonDialog)
Reset()

모든 옵션, 마지막으로 선택한 프린터 및 페이지 설정을 기본값으로 다시 설정합니다.

RunDialog(IntPtr)

파생 클래스에서 재정의되는 경우 공통 대화 상자를 지정합니다.

(다음에서 상속됨 CommonDialog)
ShowDialog()

기본 소유자와 함께 공통 대화 상자를 실행합니다.

(다음에서 상속됨 CommonDialog)
ShowDialog(IWin32Window)

지정된 소유자와 함께 공통 대화 상자를 실행합니다.

(다음에서 상속됨 CommonDialog)
ToString()

String(있는 경우)의 Component이름을 포함하는 값을 반환합니다. 이 메서드는 재정의해서는 안 됩니다.

(다음에서 상속됨 Component)

이벤트

Name Description
Disposed

구성 요소가 메서드 호출에 Dispose() 의해 삭제될 때 발생합니다.

(다음에서 상속됨 Component)
HelpRequest

사용자가 일반적인 대화 상자에서 도움말 단추를 클릭할 때 발생합니다.

(다음에서 상속됨 CommonDialog)

적용 대상

추가 정보