Share via


PrintDialog Kelas

Definisi

Memungkinkan pengguna memilih printer dan memilih bagian dokumen mana yang akan dicetak dari aplikasi Formulir Windows.

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
Warisan

Contoh

Contoh kode berikut menunjukkan cara menggunakan PrintDialog kontrol untuk mengatur AllowSomePagesproperti , ShowHelp, dan Document . Untuk menjalankan contoh ini, tempelkan kode berikut ke dalam formulir yang berisi PrintDialog kontrol bernama PrintDialog1 dan tombol bernama Button1. Contoh ini mengharuskan peristiwa tombol Click dan PrintPage peristiwa docToPrint telah terhubung ke metode penanganan peristiwa yang ditentukan dalam contoh ini.

// 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

Keterangan

Saat Anda membuat instans PrintDialog, properti baca/tulis diatur ke nilai awal. Untuk daftar nilai-nilai ini, lihat PrintDialog konstruktor. Untuk mendapatkan pengaturan printer yang dimodifikasi oleh pengguna dengan PrintDialog, gunakan PrinterSettings properti .

Untuk informasi selengkapnya tentang pencetakan dengan Formulir Windows, lihat System.Drawing.Printing gambaran umum namespace. Jika Anda ingin mencetak dari aplikasi Windows Presentation Foundation, lihat System.Printing namespace layanan.

Konstruktor

PrintDialog()

Menginisialisasi instans baru kelas PrintDialog.

Properti

AllowCurrentPage

Mendapatkan atau mengatur nilai yang menunjukkan apakah tombol opsi Halaman Saat Ini ditampilkan.

AllowPrintToFile

Mendapatkan atau mengatur nilai yang menunjukkan apakah kotak centang Cetak ke file diaktifkan.

AllowSelection

Mendapatkan atau mengatur nilai yang menunjukkan apakah tombol opsi Pilihan diaktifkan.

AllowSomePages

Mendapatkan atau mengatur nilai yang menunjukkan apakah tombol opsi Halaman diaktifkan.

CanRaiseEvents

Mendapatkan nilai yang menunjukkan apakah komponen dapat menaikkan peristiwa.

(Diperoleh dari Component)
Container

IContainer Mendapatkan yang berisi Component.

(Diperoleh dari Component)
DesignMode

Mendapatkan nilai yang menunjukkan apakah Component saat ini dalam mode desain.

(Diperoleh dari Component)
Document

Mendapatkan atau menetapkan nilai yang menunjukkan yang PrintDocument digunakan untuk mendapatkan PrinterSettings.

Events

Mendapatkan daftar penanganan aktivitas yang dilampirkan ke ini Component.

(Diperoleh dari Component)
PrinterSettings

Mendapatkan atau menyetel setelan pencetak yang diubah kotak dialog.

PrintToFile

Mendapatkan atau mengatur nilai yang menunjukkan apakah kotak centang Cetak ke file dipilih.

ShowHelp

Mendapatkan atau mengatur nilai yang menunjukkan apakah tombol Bantuan ditampilkan.

ShowNetwork

Mendapatkan atau mengatur nilai yang menunjukkan apakah tombol Jaringan ditampilkan.

Site

Mendapatkan atau mengatur ISite dari Component.

(Diperoleh dari Component)
Tag

Mendapatkan atau mengatur objek yang berisi data tentang kontrol.

(Diperoleh dari CommonDialog)
UseEXDialog

Mendapatkan atau menetapkan nilai yang menunjukkan apakah dialog harus ditampilkan dalam gaya Windows XP untuk sistem yang menjalankan Windows XP Home Edition, Windows XP Professional, Windows Server 2003 atau yang lebih baru.

Metode

CreateObjRef(Type)

Membuat objek yang berisi semua informasi relevan yang diperlukan untuk menghasilkan proksi yang digunakan untuk berkomunikasi dengan objek jarak jauh.

(Diperoleh dari MarshalByRefObject)
Dispose()

Merilis semua sumber daya yang Componentdigunakan oleh .

(Diperoleh dari Component)
Dispose(Boolean)

Merilis sumber daya tidak terkelola yang Component digunakan oleh dan secara opsional merilis sumber daya terkelola.

(Diperoleh dari Component)
Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetLifetimeService()
Kedaluwarsa.

Mengambil objek layanan seumur hidup saat ini yang mengontrol kebijakan seumur hidup untuk instans ini.

(Diperoleh dari MarshalByRefObject)
GetService(Type)

Mengembalikan objek yang mewakili layanan yang disediakan oleh Component atau oleh Container.

(Diperoleh dari Component)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

Menentukan prosedur kait kotak dialog umum yang ditimpa untuk menambahkan fungsionalitas tertentu ke kotak dialog umum.

(Diperoleh dari CommonDialog)
InitializeLifetimeService()
Kedaluwarsa.

Mendapatkan objek layanan seumur hidup untuk mengontrol kebijakan seumur hidup untuk instans ini.

(Diperoleh dari MarshalByRefObject)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
MemberwiseClone(Boolean)

Membuat salinan dangkal objek saat ini MarshalByRefObject .

(Diperoleh dari MarshalByRefObject)
OnHelpRequest(EventArgs)

Memunculkan kejadian HelpRequest.

(Diperoleh dari CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

Menentukan prosedur jendela pemilik yang ditimpa untuk menambahkan fungsionalitas tertentu ke kotak dialog umum.

(Diperoleh dari CommonDialog)
Reset()

Mereset semua opsi, printer terakhir yang dipilih, dan pengaturan halaman ke nilai defaultnya.

RunDialog(IntPtr)

Saat ditimpa di kelas turunan, menentukan kotak dialog umum.

(Diperoleh dari CommonDialog)
ShowDialog()

Menjalankan kotak dialog umum dengan pemilik default.

(Diperoleh dari CommonDialog)
ShowDialog(IWin32Window)

Menjalankan kotak dialog umum dengan pemilik yang ditentukan.

(Diperoleh dari CommonDialog)
ToString()

Mengembalikan yang String berisi nama Component, jika ada. Metode ini tidak boleh ditimpa.

(Diperoleh dari Component)

Acara

Disposed

Terjadi ketika komponen dibuang oleh panggilan ke Dispose() metode .

(Diperoleh dari Component)
HelpRequest

Terjadi ketika pengguna mengklik tombol Bantuan pada kotak dialog umum.

(Diperoleh dari CommonDialog)

Berlaku untuk

Lihat juga