Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações. |
Tradução
Original
|
Classe PrintDialog
Permite que os usuários, selecionar uma impressora e escolher quais seções do documento para imprimir a partir de um aplicativo Windows Forms.
Assembly: System.Windows.Forms (em System.Windows.Forms.dll)
Quando você cria uma instância de PrintDialog, as propriedades de leitura/gravar são conjunto valores iniciais. Para obter uma lista desses valores, consulte o PrintDialog construtor. Para obter as configurações da impressora que são modificadas pelo usuário com o PrintDialog, use o PrinterSettings propriedade.
Observação:
|
|---|
|
Essa classe pode não funcionar em microprocessadores AMD64, a menos que você conjunto o UseEXDialog propriedade para true. |
Para obter mais informações sobre como imprimir com o Windows Forms, consulte o System.Drawing.Printing namespace Visão geral. Se você quiser imprimir a partir de um aplicativo Windows Presentation Foundation, consulte o System.Printing namespace.
O exemplo de código a seguir demonstra como usar o PrintDialog controle para conjunto o AllowSomePages, ShowHelp, e Document Propriedades. Para executar esse exemplo, cole o código a seguir em um formulário que contém um PrintDialog controle de chamada PrintDialog1 e um botão denominado Button1. Este exemplo requer que Click evento e o PrintPage evento do docToPrint foram conectados aos métodos de manipulação de eventos definidos neste exemplo.
// 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.privatevoid 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.privatevoid 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 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(Object sender, System.EventArgs e)
{
// Allow the user to choose the page range he or she would
// like to print.
printDialog1.set_AllowSomePages(true);
// Show the help button.
printDialog1.set_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.set_Document(docToPrint);
DialogResult result = printDialog1.ShowDialog();
// If the result is OK then print the document.
if (result.Equals(DialogResult.OK)) {
docToPrint.Print();
}
} //button1_Click
// 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.get_Graphics().DrawString(text, printFont,
System.Drawing.Brushes.get_Black(), 10, 10);
} //Document_PrintPage
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.CommonDialog
System.Windows.Forms.PrintDialog
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.
Observação: