PrintPageEventArgs.Graphics Özellik

Tanım

Sayfayı Graphics boyamak için kullanılan öğesini alır.

C#
public System.Drawing.Graphics Graphics { get; }
C#
public System.Drawing.Graphics? Graphics { get; }

Özellik Değeri

Sayfayı Graphics boyamak için kullanılan.

Örnekler

Aşağıdaki kod örneği, üzerinde Formbir Button adlandırılmış printButton ve bir PrintDocument adlandırılmış pd oluşturulduğunu varsayar. için Button olayının Click yöntemiyle ilişkilendirildiğinden printButton_Click ve PrintPage olayının PrintDocument örnekteki yöntemle ilişkilendirildiğinden pd_PrintPage emin olun. printButton_Click Örnekteki yöntemi olayı yükselten PrintPage yöntemini çağırır Print ve yönteminde pd_PrintPage belirtilen .bmp dosyasını yazdırır. Bu örneği çalıştırmak için, yolu yazdırmak istediğiniz bit eşlem olarak değiştirin.

System.DrawingBu örnek için , System.Drawing.Printingve System.Windows.Forms ad alanlarını kullanın.

C#

// 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;
 }

Şunlara uygulanır

Ürün Sürümler
.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

Ayrıca bkz.