Thread: Printing
View Single Post
  #4 (permalink)  
Old 09-01-2006, 12:59 PM
Blaze's Avatar   
Blaze Blaze is offline
Programmer
 
Join Date: Jun 2006
Posts: 117
Rep Power: 10
Blaze is on a distinguished road
Default

Printing from C# is very easy. Here is an example:

At top:
Code:
using System.Drawing.Printing;
Print Function:
Code:
		public void Print()
		{
			PrintDocument tmpprndoc = new PrintDocument();
			tmpprndoc.PrintPage += new PrintPageEventHandler(toPrinter);

            // Load some variables
            System.Windows.Forms.PrintDialog printDialog1 = new System.Windows.Forms.PrintDialog();


            // Load the print dialog
            if(printDialog1.ShowDialog() == DialogResult.OK) 
            {

                // Change the default printer
                tmpprndoc.PrinterSettings.PrinterName = printDialog1.PrinterSettings.PrinterName;

                // Change orientation
                tmpprndoc.PrinterSettings = printDialog1.PrinterSettings;

                // Find our DPI Size (or pixels per inch)
                GetDPISize();

                // Print the document
	    		tmpprndoc.Print();

          }

}
What to print:
Code:
		private void toPrinter(Object sender, PrintPageEventArgs e)
		{
         // Create our graphics object
	Graphics g = e.Graphics;

            // Set the color of our object
	 Brush br = new SolidBrush(Color.Black);

 g.DrawString("Test Here", m_PrintFont, br, 5,5);
Reply With Quote