OKIEWARDOYO

VISUAL C# No.48 4

Sep 6th, 2014
3,595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. private void btnPrint_Click(object sender, EventArgs e)
  2. {
  3.     PrintDocument PrintDoc = new PrintDocument();
  4.     PrintDoc.PrinterSettings.PrinterName = printerList.SelectedItem.ToString();
  5.     PrintDoc.BeginPrint += new PrintEventHandler(BeginPrintEH);
  6.     PrintDoc.EndPrint += new PrintEventHandler(EndPrintEH);
  7.     PrintDoc.PrintPage += new PrintPageEventHandler(PrintPageEH);
  8.     PrintDoc.Print();
  9. }
  10.  
  11. public void BeginPrintEH(object sender, PrintEventArgs peArgs)
  12. {
  13.     redBrush = new SolidBrush(Color.Red);
  14. }
  15.  
  16. public void EndPrintEH(object sender, PrintEventArgs peArgs)
  17. {
  18.     redBrush.Dispose();
  19. }
  20.  
  21. public void PrintPageEH(object sender, PrintPageEventArgs ppeArgs)
  22. {
  23.     Graphics g = ppeArgs.Graphics;
  24.     Font font = new Font("Verdana", 20);
  25.     Rectangle rect = new Rectangle(50, 50, 200, 200);
  26.     g.DrawString("Hello Printer", font, redBrush, rect);
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment