PrintPageEventArgs.Graphics Proprietà
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene l’oggetto Graphics utilizzato per disegnare la pagina.
public:
property System::Drawing::Graphics ^ Graphics { System::Drawing::Graphics ^ get(); };
public System.Drawing.Graphics Graphics { get; }
public System.Drawing.Graphics? Graphics { get; }
member this.Graphics : System.Drawing.Graphics
Public ReadOnly Property Graphics As Graphics
Oggetto Graphics utilizzato per disegnare la pagina.
Nell'esempio di codice seguente si presuppone che sia stato creato un Button oggetto denominato e un PrintDocument denominato printButton
pd
in un oggetto Form. Verificare che l'evento per l'oggetto ClickButton sia associato al printButton_Click
metodo e che l'evento PrintPage di PrintDocument sia associato al pd_PrintPage
metodo nell'esempio. Il printButton_Click
metodo dell'esempio chiama il Print metodo che genera l'evento PrintPage e stampa il file .bmp specificato nel pd_PrintPage
metodo . Per eseguire questo esempio, modificare il percorso della bitmap da stampare.
Usare gli spazi dei System.Drawingnomi , System.Drawing.Printinge System.Windows.Forms per questo esempio.
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
Prodotto | Versioni |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Feedback su .NET
.NET è un progetto open source. Seleziona un collegamento per fornire feedback: