Ragupathi p

Ragupathi p

  • NA
  • 1
  • 0

Print a message using GDI object in the windows form in C# language

Nov 19 2010 7:07 AM

My requirement is print a message in inside of rectangle in windows form application and I achieved this one using PrintDocument and PrintDialog control.I have written the code as shown below:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Rectangle rect = new Rectangle(50, 40, 500, 150);
e.Graphics.DrawRectangle(Pens.Black, rect);
RectangleF recf = new RectangleF(55, 45, 400, 20);
e.Graphics.DrawString("Printing from Windows form",new Font("Arial",10,FontStyle.Bold ), Brushes.Black, recf);
}
My problem is If I print this message using the above code.I got the some junck line along with message but the rectange is not drawn in the print document.
The following are the output from the printer(which lines bold )
/languagelevel where {pop languagelevel} {1} ifelse dup 2 ge {currentglobal ex
0 0 10 6 [] 0 1 GpPBeg
0.0039 0.0039 0.0039 SC
NP Printing from Windows form
300 240 m 3300 240 1 330 1140 1 300 1140 1 CP
S
GSE

If I print the same message without rectangel I am able to print correct message without junk lines (above bold lines).
I am using this printer model HP LaserJet M3027 MFP PCL 6 for print
Could you please help me how to fix this issue?