次の方法で共有


方法: PageSetupDialog コンポーネントを使用してページプロパティを決定する

PageSetupDialog コンポーネントは、ドキュメントのレイアウト、用紙サイズ、その他のページ レイアウトの選択肢をユーザーに提示します。

PrintDocument クラスのインスタンスを指定する必要があります。これは印刷するドキュメントです。 さらに、ユーザーはローカルまたはネットワーク経由でコンピューターにプリンターをインストールする必要があります。これは、PageSetupDialog コンポーネントがユーザーに提示するページの書式設定の選択肢を決定する方法の一部であるためです。

PageSetupDialog コンポーネントを操作する際の重要な側面は、PageSettings クラスとの対話方法です。 PageSettings クラスは、用紙の向き、ページのサイズ、余白など、ページの印刷方法を変更する設定を指定するために使用されます。 これらの各設定は、PageSettings クラスのプロパティとして表されます。 PageSetupDialog クラスは、ドキュメントに関連付けられている (PageSettings プロパティとして表される) DefaultPageSettings クラスの特定のインスタンスに対して、これらのプロパティ値を変更します。

PageSetupDialog コンポーネントを使用してページプロパティを設定するには

  1. ShowDialog メソッドを使用してダイアログ ボックスを表示し、使用する PrintDocument を指定します。

    次の例では、Button コントロールの Click イベント ハンドラーによって、PageSetupDialog コンポーネントのインスタンスが開かれます。 Document プロパティで既存のドキュメントを指定し、その PageSettings.Color プロパティを falseに設定します。

    この例では、フォームに Button コントロール、PrintDocumentという名前の myDocument コンポーネント、および PageSetupDialog コンポーネントがあることを前提としています。

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
       ' The print document 'myDocument' used below
       ' is merely for an example.
       'You will have to specify your own print document.
       PageSetupDialog1.Document = myDocument
       ' Sets the print document's color setting to false,
       ' so that the page will not be printed in color.
       PageSetupDialog1.Document.DefaultPageSettings.Color = False
       PageSetupDialog1.ShowDialog()
    End Sub
    
    private void button1_Click(object sender, System.EventArgs e)
    {
       // The print document 'myDocument' used below
       // is merely for an example.
       // You will have to specify your own print document.
       pageSetupDialog1.Document = myDocument;
       // Sets the print document's color setting to false,
       // so that the page will not be printed in color.
       pageSetupDialog1.Document.DefaultPageSettings.Color = false;
       pageSetupDialog1.ShowDialog();
    }
    
    private:
       System::Void button1_Click(System::Object ^  sender,
          System::EventArgs ^  e)
       {
          // The print document 'myDocument' used below
          // is merely for an example.
          // You will have to specify your own print document.
          pageSetupDialog1->Document = myDocument;
          // Sets the print document's color setting to false,
          // so that the page will not be printed in color.
          pageSetupDialog1->Document->DefaultPageSettings->Color = false;
          pageSetupDialog1->ShowDialog();
       }
    

    (Visual C# と Visual C++)フォームのコンストラクターに次のコードを配置して、イベント ハンドラーを登録します。

    this.button1.Click += new System.EventHandler(this.button1_Click);
    
    this->button1->Click += gcnew
       System::EventHandler(this, &Form1::button1_Click);
    

こちらも参照ください