PrintPreviewDialog 클래스
PrintPreviewControl을 포함하는 대화 상자 폼을 나타냅니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class PrintPreviewDialog
Inherits Form
‘사용 방법
Dim instance As PrintPreviewDialog
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class PrintPreviewDialog : Form
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
public ref class PrintPreviewDialog : public Form
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
public class PrintPreviewDialog extends Form
ComVisibleAttribute(true)
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
public class PrintPreviewDialog extends Form
설명
PrintPreviewDialog 클래스의 인스턴스를 만드는 경우 일부 읽기/쓰기 속성이 초기 값으로 설정됩니다. 이러한 값에 대한 목록은 PrintPreviewDialog 생성자를 참조하십시오.
예제
다음 코드 예제에서는 Document 및 UseAntiAlias 속성을 설정하는 PrintPreviewDialog를 보여 줍니다. 이 예제에서는 폼에 TreeNode 개체를 포함하는 TreeView1
이라는 TreeView가 있다고 가정합니다. 각 TreeNode 개체의 Tag 속성은 예제를 실행하는 컴퓨터에서 액세스할 수 있는 정규화된 문서 이름으로 설정되어야 합니다. 각 TreeNode.Text 속성은 TreeNode.Tag 속성에서 지정된 파일을 식별하는 문자열로 설정합니다. 예를 들어, TreeNode1.Tag
는 "c:\myDocuments\recipe.doc"로 설정하고 TreeNode1.Text
는 "recipe.doc"로 설정할 수 있습니다. 이 예제에서는 또한 폼에 PrintPreviewDialog1
이라는 PrintPreviewDialog와 Button1
이라는 단추가 있다고 가정합니다. 이 예제를 실행하려면 폼의 생성자 또는 Load 이벤트 처리기에서 InitializePrintPreviewDialog
메서드를 호출합니다.
' Declare the dialog.
Friend WithEvents PrintPreviewDialog1 As PrintPreviewDialog
' Declare a PrintDocument object named document.
Private WithEvents document As New System.Drawing.Printing.PrintDocument
' Initalize the dialog.
Private Sub InitializePrintPreviewDialog()
' Create a new PrintPreviewDialog using constructor.
Me.PrintPreviewDialog1 = New PrintPreviewDialog
'Set the size, location, and name.
Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
Me.PrintPreviewDialog1.Location = New System.Drawing.Point(29, 29)
Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
' Set the minimum size the dialog can be resized to.
Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)
' Set the UseAntiAlias property to true, which will allow the
' operating system to smooth fonts.
Me.PrintPreviewDialog1.UseAntiAlias = True
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If Not (TreeView1.SelectedNode Is Nothing) Then
' Set the PrintDocument object's name to the selectedNode
' object's tag, which in this case contains the
' fully-qualified name of the document. This value will
' show when the dialog reports progress.
document.DocumentName = TreeView1.SelectedNode.Tag
End If
' Set the PrintPreviewDialog.Document property to
' the PrintDocument object selected by the user.
PrintPreviewDialog1.Document = document
' Call the ShowDialog method. This will trigger the document's
' PrintPage event.
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub document_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles document.PrintPage
' Insert code to render the page here.
' This code will be called when the PrintPreviewDialog.Show
' method is called.
' The following code will render a simple
' message on the document in the dialog.
Dim text As String = "In document_PrintPage method."
Dim printFont As New System.Drawing.Font _
("Arial", 35, System.Drawing.FontStyle.Regular)
e.Graphics.DrawString(text, printFont, _
System.Drawing.Brushes.Black, 0, 0)
End Sub
// Declare the dialog.
internal PrintPreviewDialog PrintPreviewDialog1;
// Declare a PrintDocument object named document.
private System.Drawing.Printing.PrintDocument document =
new System.Drawing.Printing.PrintDocument();
// Initalize the dialog.
private void InitializePrintPreviewDialog()
{
// Create a new PrintPreviewDialog using constructor.
this.PrintPreviewDialog1 = new PrintPreviewDialog();
//Set the size, location, and name.
this.PrintPreviewDialog1.ClientSize =
new System.Drawing.Size(400, 300);
this.PrintPreviewDialog1.Location =
new System.Drawing.Point(29, 29);
this.PrintPreviewDialog1.Name = "PrintPreviewDialog1";
// Associate the event-handling method with the
// document's PrintPage event.
this.document.PrintPage +=
new System.Drawing.Printing.PrintPageEventHandler
(document_PrintPage);
// Set the minimum size the dialog can be resized to.
this.PrintPreviewDialog1.MinimumSize =
new System.Drawing.Size(375, 250);
// Set the UseAntiAlias property to true, which will allow the
// operating system to smooth fonts.
this.PrintPreviewDialog1.UseAntiAlias = true;
}
private void Button1_Click(object sender, System.EventArgs e)
{
if (TreeView1.SelectedNode != null)
// Set the PrintDocument object's name to the selectedNode
// object's tag, which in this case contains the
// fully-qualified name of the document. This value will
// show when the dialog reports progress.
{
document.DocumentName = TreeView1.SelectedNode.Tag.ToString();
}
// Set the PrintPreviewDialog.Document property to
// the PrintDocument object selected by the user.
PrintPreviewDialog1.Document = document;
// Call the ShowDialog method. This will trigger the document's
// PrintPage event.
PrintPreviewDialog1.ShowDialog();
}
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 PrintPreviewDialog.Show
// method is called.
// The following code will render a simple
// message on the document in the dialog.
string text = "In document_PrintPage method.";
System.Drawing.Font printFont =
new System.Drawing.Font("Arial", 35,
System.Drawing.FontStyle.Regular);
e.Graphics.DrawString(text, printFont,
System.Drawing.Brushes.Black, 0, 0);
}
// Declare the dialog.
internal:
PrintPreviewDialog^ PrintPreviewDialog1;
private:
// Declare a PrintDocument object named document.
System::Drawing::Printing::PrintDocument^ document;
// Initalize the dialog.
void InitializePrintPreviewDialog()
{
// Create a new PrintPreviewDialog using constructor.
this->PrintPreviewDialog1 = gcnew PrintPreviewDialog;
//Set the size, location, and name.
this->PrintPreviewDialog1->ClientSize = System::Drawing::Size( 400, 300 );
this->PrintPreviewDialog1->Location = System::Drawing::Point( 29, 29 );
this->PrintPreviewDialog1->Name = "PrintPreviewDialog1";
// Associate the event-handling method with the
// document's PrintPage event.
this->document->PrintPage += gcnew System::Drawing::Printing::PrintPageEventHandler( this, &Form1::document_PrintPage );
// Set the minimum size the dialog can be resized to.
this->PrintPreviewDialog1->MinimumSize = System::Drawing::Size( 375, 250 );
// Set the UseAntiAlias property to true, which will allow the
// operating system to smooth fonts.
this->PrintPreviewDialog1->UseAntiAlias = true;
}
void Button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
if ( TreeView1->SelectedNode != nullptr )
{
document->DocumentName = TreeView1->SelectedNode->Tag->ToString();
}
// Set the PrintPreviewDialog.Document property to
// the PrintDocument object selected by the user.
PrintPreviewDialog1->Document = document;
// Call the ShowDialog method. This will trigger the document's
// PrintPage event.
PrintPreviewDialog1->ShowDialog();
}
void document_PrintPage( Object^ /*sender*/, System::Drawing::Printing::PrintPageEventArgs^ e )
{
// Insert code to render the page here.
// This code will be called when the PrintPreviewDialog.Show
// method is called.
// The following code will render a simple
// message on the document in the dialog.
String^ text = "In document_PrintPage method.";
System::Drawing::Font^ printFont = gcnew System::Drawing::Font( "Arial",35,System::Drawing::FontStyle::Regular );
e->Graphics->DrawString( text, printFont, System::Drawing::Brushes::Black, 0, 0 );
}
// Declare the dialog.
PrintPreviewDialog printPreviewDialog1;
// Declare a PrintDocument object named document.
private System.Drawing.Printing.PrintDocument document =
new System.Drawing.Printing.PrintDocument();
// Initalize the dialog.
private void InitializePrintPreviewDialog()
{
// Create a new PrintPreviewDialog using constructor.
this.printPreviewDialog1 = new PrintPreviewDialog();
//Set the size, location, and name.
this.printPreviewDialog1.set_ClientSize(
new System.Drawing.Size(400, 300));
this.printPreviewDialog1.set_Location(new System.Drawing.Point(29, 29));
this.printPreviewDialog1.set_Name("PrintPreviewDialog1");
// Associate the event-handling method with the
// document's PrintPage event.
this.document.add_PrintPage(
new System.Drawing.Printing.PrintPageEventHandler(
document_PrintPage));
// Set the minimum size the dialog can be resized to.
this.printPreviewDialog1.set_MinimumSize(
new System.Drawing.Size(375, 250));
// Set the UseAntiAlias property to true, which will allow the
// operating system to smooth fonts.
this.printPreviewDialog1.set_UseAntiAlias(true);
} //InitializePrintPreviewDialog
private void button1_Click(Object sender, System.EventArgs e)
{
if (treeView1.get_SelectedNode() != null) {
// Set the PrintDocument object's name to the selectedNode
// object's tag, which in this case contains the
// fully-qualified name of the document. This value will
// show when the dialog reports progress.
document.set_DocumentName(
treeView1.get_SelectedNode().get_Tag().ToString());
}
// Set the PrintPreviewDialog.Document property to
// the PrintDocument object selected by the user.
printPreviewDialog1.set_Document(document);
// Call the ShowDialog method. This will trigger the document's
// PrintPage event.
printPreviewDialog1.ShowDialog();
} //button1_Click
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 PrintPreviewDialog.Show
// method is called.
// The following code will render a simple
// message on the document in the dialog.
String text = "In document_PrintPage method.";
System.Drawing.Font printFont =
new System.Drawing.Font("Arial", 35,
System.Drawing.FontStyle.Regular);
e.get_Graphics().DrawString(text, printFont,
System.Drawing.Brushes.get_Black(), 0, 0);
} //document_PrintPage
상속 계층 구조
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ContainerControl
System.Windows.Forms.Form
System.Windows.Forms.PrintPreviewDialog
스레드로부터의 안전성
이 형식의 모든 public static(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에서 지원
참고 항목
참조
PrintPreviewDialog 멤버
System.Windows.Forms 네임스페이스
PageSetupDialog 클래스
PrintDialog 클래스
PrintPreviewControl 클래스