Files
Andy De George c0ba284473 Initial winforms content migrated (#18)
* 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
2020-09-01 16:26:21 -07:00

2.5 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Print Graphics 03/30/2017
csharp
vb
cpp
graphics [Windows Forms], printing
printing [Windows Forms], graphics
32b891e6-52ff-4fea-a9ff-2ce5db20a4c6

How to: Print Graphics in Windows Forms

Frequently, you will want to print graphics in your Windows-based application. The xref:System.Drawing.Graphics class provides methods for drawing objects to a device, such as a screen or printer.

To print graphics

  1. Add a xref:System.Drawing.Printing.PrintDocument component to your form.

  2. In the xref:System.Drawing.Printing.PrintDocument.PrintPage event handler, use the xref:System.Drawing.Printing.PrintPageEventArgs.Graphics%2A property of the xref:System.Drawing.Printing.PrintPageEventArgs class to instruct the printer on what kind of graphics to print.

    The following code example shows an event handler used to create a blue ellipse within a bounding rectangle. The rectangle has the following location and dimensions: beginning at 100, 150 with a width of 250 and a height of 250.

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage  
       e.Graphics.FillEllipse(Brushes.Blue, New Rectangle(100, 150, 250, 250))  
    End Sub  
    
    private void printDocument1_PrintPage(object sender,
    System.Drawing.Printing.PrintPageEventArgs e)  
    {  
       e.Graphics.FillRectangle(Brushes.Blue,
         new Rectangle(100, 150, 250, 250));  
    }  
    
    private:  
       void printDocument1_PrintPage(System::Object ^ sender,  
          System::Drawing::Printing::PrintPageEventArgs ^ e)  
       {  
          e->Graphics->FillRectangle(Brushes::Blue,  
             Rectangle(100, 150, 250, 250));  
       }  
    

    (Visual C# and Visual C++) Place the following code in the form's constructor to register the event handler.

    this.printDocument1.PrintPage += new  
       System.Drawing.Printing.PrintPageEventHandler  
       (this.printDocument1_PrintPage);  
    
    this->printDocument1->PrintPage += gcnew  
       System::Drawing::Printing::PrintPageEventHandler  
       (this, &Form1::printDocument1_PrintPage);  
    

See also