* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
4.8 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| How to: Determine Page Properties Using the PageSetupDialog Component | 03/30/2017 |
|
|
6dae05bc-c0fd-4357-bb93-841a1631d98f |
How to: Determine Page Properties Using the PageSetupDialog Component
The PageSetupDialog component presents layout, paper size, and other page layout choices to the user for a document.
You need to specify an instance of the xref:System.Drawing.Printing.PrintDocument class—this is the document to be printed. Additionally, users must have a printer installed on their computer, either locally or through a network, as this is partly how the xref:System.Windows.Forms.PageSetupDialog component determines the page formatting choices presented to the user.
An important aspect of working with the xref:System.Windows.Forms.PageSetupDialog component is how it interacts with the xref:System.Drawing.Printing.PageSettings class. The xref:System.Drawing.Printing.PageSettings class is used to specify settings that modify the way a page will be printed, such as paper orientation, the size of the page, and the margins. Each of these settings is represented as a property of the xref:System.Drawing.Printing.PageSettings class. The xref:System.Windows.Forms.PageSetupDialog class modifies these property values for a given instance of the xref:System.Drawing.Printing.PageSettings class that is associated with the document (and is represented as a xref:System.Drawing.Printing.PrintDocument.DefaultPageSettings%2A property).
To set page properties using the PageSetupDialog component
-
Use the xref:System.Windows.Forms.CommonDialog.ShowDialog%2A method to display the dialog box, specifying the xref:System.Drawing.Printing.PrintDocument to use.
In the example below, the xref:System.Windows.Forms.Button control's xref:System.Windows.Forms.Control.Click event handler opens an instance of the xref:System.Windows.Forms.PageSetupDialog component. An existing document is specified in the xref:System.Windows.Forms.PageSetupDialog.Document%2A property, and its xref:System.Drawing.Printing.PageSettings.Color%2A?displayProperty=nameWithType property is set to
false.The example assumes your form has a xref:System.Windows.Forms.Button control, a xref:System.Drawing.Printing.PrintDocument component named
myDocument, and a xref:System.Windows.Forms.PageSetupDialog component.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 Subprivate 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# and Visual C++) Place the following code in the form's constructor to register the event handler.
this.button1.Click += new System.EventHandler(this.button1_Click);this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);