Click here to Skip to main content
15,918,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends. Could you please help me to drawing shapes and objects in printdocument at runtime?
Posted

In the PrintDocument PrintPage event handler, use the PrintPageEventArgs.Graphics object:
private void pd_PrintPage(object sender, PrintPageEventArgs e) 
   {      
   // Draw a picture.
   e.Graphics.DrawImage(Image.FromFile(@"F:\Temp\MyPicture.bmp"), e.Graphics.VisibleClipBounds);
   e.Graphics.DrawRectangle(myPen, myRectangle);
   e.Graphics.DrawString("Hello!", myFont, myBrush, myPoint);
   e.HasMorePages = false;  //Last page
   }


[edit]Strange - the close bracket would not stay where I put it... - OriginalGriff[/edit]
 
Share this answer
 
v2
This Drawing Lines and Shapes with GDI+[^] should get you started. You just need to add put these methods into effect in the PrintDocument.PrintPage() event, and you should be printing in no time.

Happy Coding
 
Share this answer
 
v3
Comments
OriginalGriff 6-May-11 3:13am    
The PrintDocument.Print method is an instruction to the PrintDocument to start printing, and not something you can draw in! http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.print(v=VS.85).aspx contains a full example...
Wayne Gaylard 6-May-11 3:25am    
Sorry, you're right, I meant the PrintPage event. Fixed it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900