John Smith
12/1/2004 6:17:00 PM
Hey folks,
Frustration level rising here.
I'm trying to print to a printer from a C# windows application.
First though, from Notepad, I format some text (i.e. put in tabs and spaces
to get it to the proper location on the page), go to Print, choose my
printer, set the page size width to 7 inches and height to 3.5 inches. I
also set the orientation to landscape. I remove all margins and print.
Comes out perfect.
I'm trying to recreate that in code, but it's not coming out right. Here's
what I'm doing. Is there anything wrong?
printDoc.PrinterSettings.PrinterName = configSettings.labelPrinterName;
printDoc.DefaultPageSettings.Landscape = true;
printDoc.DefaultPageSettings.PaperSize.Width = 700;
printDoc.DefaultPageSettings.PaperSize.Height = 350;
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
printDoc.Print();
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e){
e.PageSettings.PaperSize.Width = 700;
e.PageSettings.PaperSize.Height = 350;
e.PageSettings.Landscape = true;
Font printFont = new Font("Arial", 10, System.Drawing.FontStyle.Bold);
e.Graphics.DrawString(strTextToPrint, printFont, Brushes.Black, 0, 0);
}