PrintPreviewControl Class
Represents the raw preview part of print previewing from a Windows Forms application, without any dialog boxes or buttons. Most PrintPreviewControl objects are found on PrintPreviewDialog objects, but they do not have to be.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
When you create an instance of the PrintPreviewControl class, some of the read/write properties are set to initial values. For a list of these values, see the PrintPreviewControl constructor.
For more information about printing with Windows Forms, see the System.Drawing.Printing namespace overview. If you wish to print from a Windows Presentation Foundation application, see the System.Printing namespace.
The following code example demonstrates the Document, UseAntiAlias, and Zoom properties of the PrintPreviewControl. To run this example, place the following code in a form and call the InitializePrintPreviewControl method from the form’s constructor or Load event-handling method.
'Declare the PrintPreviewControl object and the PrintDocument object. Friend WithEvents PrintPreviewControl1 As PrintPreviewControl Private WithEvents docToPrint As New Printing.PrintDocument Private Sub InitializePrintPreviewControl() ' Construct the PrintPreviewControl. Me.PrintPreviewControl1 = New PrintPreviewControl ' Set location, name, and dock style for PrintPreviewControl1. Me.PrintPreviewControl1.Location = New Point(88, 80) Me.PrintPreviewControl1.Name = "PrintPreviewControl1" Me.PrintPreviewControl1.Dock = DockStyle.Fill ' Set the Document property to the PrintDocument ' for which the PrintPage event has been handled. Me.PrintPreviewControl1.Document = docToPrint ' Set the zoom to 25 percent. Me.PrintPreviewControl1.Zoom = 0.25 ' Set the document name. This will show be displayed when ' the document is loading into the control. Me.PrintPreviewControl1.Document.DocumentName = "c:\someFile" ' Set the UseAntiAlias property to true so fonts are smoothed ' by the operating system. Me.PrintPreviewControl1.UseAntiAlias = True ' Add the control to the form. Me.Controls.Add(Me.PrintPreviewControl1) End Sub ' The PrintPreviewControl will display the document ' by handling the documents PrintPage event Private Sub docToPrint_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 document in the control. Dim text As String = "In docToPrint_PrintPage method." Dim printFont As New Font _ ("Arial", 35, System.Drawing.FontStyle.Regular) e.Graphics.DrawString(text, printFont, _ System.Drawing.Brushes.Black, 10, 10) End Sub
PrintPreviewControl class. To run this example place the following code in a form and call the InitializePrintPreviewControl method from the form’s constructor or Load method.
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.PrintPreviewControl
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.