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 PrintPreviewControl
Representa a parte de visualização de impressão de um aplicativo Windows Forms, sem caixas de diálogo ou botões de visualização não processados. A maioria dos PrintPreviewControl objetos são encontrados em PrintPreviewDialog objetos, mas não precisa ser.
Assembly: System.Windows.Forms (em System.Windows.Forms.dll)
Quando você cria uma instância do PrintPreviewControl classe, algumas das propriedades de leitura/gravar são conjunto valores iniciais. Para obter uma lista desses valores, consulte o PrintPreviewControl construtor.
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 espaço para nome.
O exemplo de código a seguir demonstra o Document, UseAntiAlias, e Zoom propriedades das PrintPreviewControl. Para executar esse exemplo, coloque o código a seguir em um formulário e telefonar o InitializePrintPreviewControl método do construtor do formulário ou Load método de manipulação de eventos.
// Declare the PrintPreviewControl object and the // PrintDocument object.internal PrintPreviewControl PrintPreviewControl1; private System.Drawing.Printing.PrintDocument docToPrint = new System.Drawing.Printing.PrintDocument(); privatevoid InitializePrintPreviewControl() { // Construct the PrintPreviewControl.this.PrintPreviewControl1 = new PrintPreviewControl(); // Set location, name, and dock style for PrintPreviewControl1.this.PrintPreviewControl1.Location = new Point(88, 80); this.PrintPreviewControl1.Name = "PrintPreviewControl1"; this.PrintPreviewControl1.Dock = DockStyle.Fill; // Set the Document property to the PrintDocument // for which the PrintPage event has been handled.this.PrintPreviewControl1.Document = docToPrint; // Set the zoom to 25 percent.this.PrintPreviewControl1.Zoom = 0.25; // Set the document name. This will show be displayed when // the document is loading into the control.this.PrintPreviewControl1.Document.DocumentName = "c:\\someFile"; // Set the UseAntiAlias property to true so fonts are smoothed// by the operating system.this.PrintPreviewControl1.UseAntiAlias = true; // Add the control to the form.this.Controls.Add(this.PrintPreviewControl1); // Associate the event-handling method with the// document's PrintPage event.this.docToPrint.PrintPage += new System.Drawing.Printing.PrintPageEventHandler( docToPrint_PrintPage); } // The PrintPreviewControl will display the document// by handling the documents PrintPage eventprivatevoid docToPrint_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 document in the control. string text = "In docToPrint_PrintPage method."; System.Drawing.Font printFont = new Font("Arial", 35, FontStyle.Regular); e.Graphics.DrawString(text, printFont, Brushes.Black, 10, 10); }
// Declare the PrintPreviewControl object and the
// PrintDocument object.
PrintPreviewControl printPreviewControl1;
private System.Drawing.Printing.PrintDocument docToPrint =
new System.Drawing.Printing.PrintDocument();
private void InitializePrintPreviewControl()
{
// Construct the PrintPreviewControl.
this.printPreviewControl1 = new PrintPreviewControl();
// Set location, name, and dock style for PrintPreviewControl1.
this.printPreviewControl1.set_Location(new Point(88, 80));
this.printPreviewControl1.set_Name("PrintPreviewControl1");
this.printPreviewControl1.set_Dock(DockStyle.Fill);
// Set the Document property to the PrintDocument
// for which the PrintPage event has been handled.
this.printPreviewControl1.set_Document(docToPrint);
// Set the zoom to 25 percent.
this.printPreviewControl1.set_Zoom(0.25);
// Set the document name. This will show be displayed when
// the document is loading into the control.
this.printPreviewControl1.get_Document().set_DocumentName("c:\\someFile");
// Set the UseAntiAlias property to true so fonts are smoothed
// by the operating system.
this.printPreviewControl1.set_UseAntiAlias(true);
// Add the control to the form.
this.get_Controls().Add(this.printPreviewControl1);
// Associate the event-handling method with the
// document's PrintPage event.
this.docToPrint.add_PrintPage(
new System.Drawing.Printing.PrintPageEventHandler(
docToPrint_PrintPage));
} //InitializePrintPreviewControl
// The PrintPreviewControl will display the document
// by handling the documents PrintPage event
private void docToPrint_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 document in the control.
String text = "In docToPrint_PrintPage method.";
System.Drawing.Font printFont = new Font("Arial", 35, FontStyle.Regular);
e.get_Graphics().DrawString(text, printFont, Brushes.get_Black(), 10, 10);
} //docToPrint_PrintPage
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.PrintPreviewControl
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.