方法: 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);
関連項目
.NET Desktop feedback
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示