PrintPageEventArgs.Graphics Proprietà

Definizione

Ottiene l’oggetto Graphics utilizzato per disegnare la pagina.Gets the Graphics used to paint the page.

public:
 property System::Drawing::Graphics ^ Graphics { System::Drawing::Graphics ^ get(); };
public System.Drawing.Graphics Graphics { get; }
member this.Graphics : System.Drawing.Graphics
Public ReadOnly Property Graphics As Graphics

Valore della proprietà

Oggetto Graphics utilizzato per disegnare la pagina.The Graphics used to paint the page.

Esempi

Nell'esempio di codice seguente si Button presuppone printButton che un oggetto pd denominato e un oggetto PrintDocument denominato Formsiano stati creati in un oggetto.The following code example assumes a Button named printButton and a PrintDocument named pd have been created on a Form. Verificare che l' Click evento Button per sia associato printButton_Click al metodo e che pd_PrintPage l' PrintPage evento di PrintDocument sia associato al metodo nell'esempio.Make sure the Click event for the Button is associated with the printButton_Click method and the PrintPage event of the PrintDocument is associated with the pd_PrintPage method in the example. Il printButton_Click metodo dell'esempio chiama il Print metodo che genera l' PrintPage evento e pd_PrintPage stampa il file con estensione bmp specificato nel metodo.The printButton_Click method from the example calls the Print method raising the PrintPage event, and prints the .bmp file specified in the pd_PrintPage method. Per eseguire questo esempio, modificare il percorso della bitmap che si desidera stampare.To run this example, change the path to the bitmap you want to print.

Usare gli System.Drawingspazi System.Drawing.Printingdei nomi System.Windows.Forms , e per questo esempio.Use the System.Drawing, System.Drawing.Printing, and System.Windows.Forms namespaces for this example.

private:
   // Specifies what happens when the user clicks the Button.
   void printButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      try
      {
         pd->Print();
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( "An error occurred while printing", ex->ToString() );
      }
   }

   // Specifies what happens when the PrintPage event is raised.
   void pd_PrintPage( Object^ /*sender*/, PrintPageEventArgs^ ev )
   {
      // Draw a picture.
      ev->Graphics->DrawImage( Image::FromFile( "C:\\My Folder\\MyFile.bmp" ),
         ev->Graphics->VisibleClipBounds );
      
      // Indicate that this is the last page to print.
      ev->HasMorePages = false;
   }

// Specifies what happens when the user clicks the Button.
 private void printButton_Click(object sender, EventArgs e) 
 {
   try 
   {
     // Assumes the default printer.
     pd.Print();
   }  
   catch(Exception ex) 
   {
     MessageBox.Show("An error occurred while printing", ex.ToString());
   }
 }
 
 // Specifies what happens when the PrintPage event is raised.
 private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
 {      
   // Draw a picture.
   ev.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);
      
   // Indicate that this is the last page to print.
   ev.HasMorePages = false;
 }

    
' Specifies what happens when the user clicks the Button.
Private Sub printButton_Click(sender As Object, e As EventArgs) _
Handles printButton.Click
    Try
       pd.Print()
    Catch ex As Exception
        MessageBox.Show("An error occurred while printing", _
            ex.ToString())
    End Try
End Sub    

' Specifies what happens when the PrintPage event is raised.
Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs) _
Handles pd.PrintPage

    ' Draw a picture.
    ev.Graphics.DrawImage(Image.FromFile("C:\My Folder\MyFile.bmp"), _
        ev.Graphics.VisibleClipBounds)
    
    ' Indicate that this is the last page to print.
    ev.HasMorePages = False
End Sub

Si applica a

Vedi anche