PrintDocument.DocumentName : PrintDocument « System.Drawing.Printing « C# / C Sharp by API






PrintDocument.DocumentName

 
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
   
class HelloPrinter: Form
{
     public static void Main()
     {
          Application.Run(new HelloPrinter());
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics     grfx   = pea.Graphics;
          StringFormat strfmt = new StringFormat();
          grfx.DrawString("Click to print", Font, new SolidBrush(ForeColor),ClientRectangle, strfmt);
     }
     protected override void OnClick(EventArgs ea)
     {
          PrintDocument prndoc = new PrintDocument();
   
          prndoc.DocumentName = Text;
          prndoc.PrintPage += new PrintPageEventHandler(PrintDocumentOnPrintPage);
          prndoc.Print();
     }
     void PrintDocumentOnPrintPage(object obj, PrintPageEventArgs ppea)
     {
          Graphics grfx = ppea.Graphics;
          grfx.DrawString(Text, Font, Brushes.Black, 0, 0);
          SizeF sizef = grfx.MeasureString(Text, Font);
          grfx.DrawLine(Pens.Black, sizef.ToPointF(), grfx.VisibleClipBounds.Size.ToPointF());
     }
}

   
  








Related examples in the same category

1.new PrintDocument()
2.extends PrintDocument
3.PrintDocument.DefaultPageSettings
4.PrintDocument.Print()
5.PrintDocument.PrintPage