PrintPreviewControl 类
表示打印预览的原始预览部分,没有任何对话框或按钮。大多数 PrintPreviewControl 对象都可在 PrintPreviewDialog 对象上找到,但这不是必需的。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class PrintPreviewControl
Inherits Control
用法
Dim instance As PrintPreviewControl
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class PrintPreviewControl : Control
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
public ref class PrintPreviewControl : public Control
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
public class PrintPreviewControl extends Control
ComVisibleAttribute(true)
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
public class PrintPreviewControl extends Control
备注
在创建 PrintPreviewControl 类的实例时,一些读/写属性被设置为初始值。有关这些值的列表,请参见 PrintPreviewControl 构造函数。
示例
下面的代码示例演示 PrintPreviewControl 的 Document、UseAntiAlias 和 Zoom 属性。若要运行此示例,请将下面的代码放到一个窗体中,并调用位于该窗体的构造函数或 Load 事件处理方法中的 InitializePrintPreviewControl
方法。
'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
// Declare the PrintPreviewControl object and the
// PrintDocument object.
internal 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.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 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.Graphics.DrawString(text, printFont,
Brushes.Black, 10, 10);
}
internal:
// Declare the PrintPreviewControl object and the
// PrintDocument object.
PrintPreviewControl^ PrintPreviewControl1;
private:
System::Drawing::Printing::PrintDocument^ docToPrint;
void InitializePrintPreviewControl()
{
// Construct the PrintPreviewControl.
this->PrintPreviewControl1 = gcnew PrintPreviewControl;
// Set location, name, and dock style for PrintPreviewControl1.
this->PrintPreviewControl1->Location = 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 += gcnew System::Drawing::Printing::PrintPageEventHandler( this, &Form1::docToPrint_PrintPage );
}
// The PrintPreviewControl will display the document
// by handling the documents PrintPage event
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 = gcnew System::Drawing::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.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.PrintPreviewControl
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
PrintPreviewControl 成员
System.Windows.Forms 命名空间
PrintPreviewDialog