次の方法で共有


PrintPreviewDialog クラス

PrintPreviewControl を含むダイアログ ボックス フォームを表します。

この型のすべてのメンバの一覧については、PrintPreviewDialog メンバ を参照してください。

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 Class PrintPreviewDialog
   Inherits Form
[C#]
public class PrintPreviewDialog : Form
[C++]
public __gc class PrintPreviewDialog : public Form
[JScript]
public class PrintPreviewDialog extends Form

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

PrintPreviewDialog のインスタンスを作成すると、一部の読み書き可能プロパティが初期値に設定されます。これらの初期値の一覧については、 PrintPreviewDialog コンストラクタのトピックを参照してください。

使用例

[Visual Basic, C#] 次のコード例は、TreeView1 という名前の TreeView が配置されているフォームがあることを前提としています。この TreeView には TreeNode のオブジェクトが格納されています。各 TreeNode オブジェクトの Tag プロパティには、完全限定のドキュメント名を設定する必要があります。このドキュメント名には、この例を実行するコンピュータからアクセスできます。各 Text プロパティには、Tag プロパティによって指定されたファイルを識別するための文字列を設定します。たとえば、TreeNode1.Tag には "c:\myDocuments\recipe.doc" を、TreeNode1.Text には "recipe.doc" を設定できます。また、このフォームに、PrintPreviewDialog1 という名前の PrintPreviewDialog オブジェクトと Button1 という名前のボタンが配置されていることも前提としています。この例を実行するには、フォームのコンストラクタで 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

[C#] 

    // 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);

    }

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Windows.Forms

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

PrintPreviewDialog メンバ | System.Windows.Forms 名前空間 | PageSetupDialog | PrintDialog | PrintPreviewControl