PrintFontSample.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Sample to Print diferent font types and sizes
  3. //
  4. using System;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Drawing.Printing;
  8. public class PrintingTextFile
  9. {
  10. static private void PrintPageEvent (object sender, PrintPageEventArgs e)
  11. {
  12. float left = e.MarginBounds.Left;
  13. float top = e.MarginBounds.Top;
  14. Font font = new Font ("Arial", 10);
  15. e.Graphics.DrawString("This a sample with font " + font.Name + " size:" + font.Size,
  16. font, new SolidBrush (Color.Red), left, top);
  17. font = new Font ("Verdana", 16);
  18. e.Graphics.DrawString ("This a sample with font " + font.Name + " size:" + font.Size,
  19. font, new SolidBrush (Color.Blue), left, top + 50);
  20. font = new Font ("Verdana", 22);
  21. e.Graphics.DrawString ("This a sample with font " + font.Name + " size:" + font.Size,
  22. font, new SolidBrush (Color.Black), left, top + 150);
  23. font = new Font (FontFamily.GenericMonospace, 14);
  24. e.Graphics.DrawString ("This a sample with font " + font.Name + " size:" + font.Size,
  25. font, new SolidBrush (Color.Black), left, top + 250);
  26. font = new Font ("Arial", 48);
  27. e.Graphics.DrawString ("Font " + font.Name + " size:" + font.Size,
  28. font, new SolidBrush (Color.Red), left, top + 300);
  29. font = new Font ("Times New Roman", 32);
  30. e.Graphics.DrawString ("Another sample font " + font.Name + " size:" + font.Size,
  31. font, new SolidBrush (Color.Black), left, top + 500);
  32. font = new Font (FontFamily.GenericSansSerif, 8);
  33. e.Graphics.DrawString ("Another sample font " + font.Name + " size:" + font.Size,
  34. font, new SolidBrush (Color.Blue), left, top + 900);
  35. e.HasMorePages = false;
  36. }
  37. public static void Main (string[] args)
  38. {
  39. PrintDocument p = new PrintDocument ();
  40. p.PrintPage += new PrintPageEventHandler (PrintPageEvent);
  41. p.Print ();
  42. }
  43. }