Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
Versions précédentes
.NET Framework 3.0
Windows Forms
 Comment : imprimer des graphiques d...

  Passer à l'affichage pour faible bande passante
Cette page est spécifique à
.NET Framework 3.0

D'autres versions sont également disponibles pour :
Programmation Windows Forms
Comment : imprimer des graphiques dans Windows Forms

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

To print graphics

  1. Add a PrintDocument component to your form.

  2. In the PrintPage event handler, use the Graphics property of the 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.

    Visual Basic
    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
    
    

    C#
    private void printDocument1_PrintPage(object sender, 
    System.Drawing.Printing.PrintPageEventArgs e)
    {
       e.Graphics.FillRectangle(Brushes.Blue, 
         new Rectangle(100, 150, 250, 250));
    }
    
    

    J#
    private void printDocument1_PrintPage(Object sender,
    System.Drawing.Printing.PrintPageEventArgs e)
    {
       e.get_Graphics().FillRectangle(Brushes.get_Blue(),
          new Rectangle(100, 150, 250, 250));
    }
    
    

    C++
    private:
       void printDocument1_PrintPage(System::Object ^ sender,
          System::Drawing::Printing::PrintPageEventArgs ^ e)
       {
          e->Graphics->FillRectangle(Brushes::Blue,
             Rectangle(100, 150, 250, 250));
       }
    

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

    C#
    this.printDocument1.PrintPage += new
       System.Drawing.Printing.PrintPageEventHandler
       (this.printDocument1_PrintPage);
    

    J#
    this.printDocument1.add_PrintPage(new System.Drawing.Printing.PrintPageEventHandler(
    this.printDocument1_PrintPage));
    

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

Voir aussi

Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2009 Microsoft Corporation. Tous droits réservés. Conditions d'utilisation  |  Marques  |  Confidentialité
Page view tracker