次の方法で共有


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

PageSetupDialog コンポーネントを使用すると、ドキュメントのレイアウト、用紙サイズ、およびその他のページ レイアウトをユーザーが選択できるようになります。

PrintDocument クラスのインスタンスを指定する必要があります。これは印刷されるドキュメントです。 また、ユーザーはコンピューター上にプリンターをローカルまたはネットワーク経由でインストールしている必要があります。PageSetupDialog コンポーネントはこのプリンターに基づいて、ユーザーに提供するページ形式の選択肢を決定します。

PageSetupDialog コンポーネントを使用する場合に重要な点は、このコンポーネントが PageSettings クラスとどのようにやり取りするかという点です。 PageSettings クラスは、用紙の向き、ページのサイズ、余白など、ページの印刷方法を変更する設定を指定するために使用されます。 これらの各設定は、PageSettings クラスのプロパティとして表されます。 PageSetupDialog クラスは、ドキュメントに関連付けられた PageSettings クラスのインスタンスに対してこれらのプロパティを変更します。このインスタンスは DefaultPageSettings プロパティとして表されます。

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

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

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

    この例のコードは、フォームに Button コントロール、 myDocument という名前の PrintDocument コンポーネント、および 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);
    

参照

処理手順

方法 : 標準の Windows フォーム印刷ジョブを作成する

参照

PageSetupDialog

その他の技術情報

PageSetupDialog コンポーネント (Windows フォーム)