Jump to content

Printing

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Chan

Chan

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 204 posts
In addition to my barcodes thread at: http://forum.codecal...7-barcodes.html

I also need to print these barcodes. Is there a built-in .NET class that allows me to print? Or will I have to create my own connection to the printer?

#2
hoser2001

hoser2001

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
http://www.c-sharpco...rCodingInCS.asp
--this article has a good article for barcodes

http://www.c-sharpco.../texteditor.asp
--this has small demo of how to print the contents of a textbox in C#

Hope this stuff helps out!

#3
Ronin

Ronin

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 309 posts
Yes, there are tons of tutorials out there for printing from C#. You can find just about anything in C# if you search for it....

#4
Blaze

Blaze

    Programmer

  • Members
  • PipPipPipPip
  • 117 posts
Printing from C# is very easy. Here is an example:

At top:
using System.Drawing.Printing;

Print Function:
		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:
		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);