[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

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);

}




1 Answer

Morten Wennevik [C# MVP]

12/1/2004 6:39:00 PM

0

Hi John,

You don't say what is wrong with your the print and I can't see anything
wrong with the code either.
You might try to set the size property as a size instead of the individual
height and width.

printDoc.DefaultPageSettings.PaperSize = new PaperSize(700, 350);
....
e.PageSettings.PaperSize = new PaperSize(700, 350);
// no need to set individual page size unless the page sizes will change
mid print job

I suspect you actually want to change DefaultPageSettings.Margins as the
papersize is the physical size of the paper (letter, A4, A5 etc).

--
Happy Coding!
Morten Wennevik [C# MVP]