Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have windows form. On form canvas, I am drawing muliple rectangles and lines.
I want so suport sprint functionlity, which will print images drawn on for canvas.

There is one alternative that
1.We can create image using
CopyFromScreen
and then add to print doucment and print it. When we create .jpeg the qulity of image is not good and which is not displayed properly.

Is there other best alternative which will make sure that display qulity will maintain. ?




Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 8-Apr-13 10:48am    
Is it System.Windows.Forma? Tag it: "WinForm".
—SA

1 solution

If this is System.Windows.Forms, you can use the class System.Drawing.Printing.PrintDocument:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

If you want to print something which is already drawn on screen, you should abstract out your rendering method as some separate method abstracted from the nature of the instance of System.Drawing.Graphics, passing such instance as a parameter, along with some other required parameters, say, to pass a clip region to draw in, or perhaps other detail:

C#
void Render(System.Drawing.Graphics graphics, Rectangle drawingArea /* , ... */) {
   // draw here
}


This way, you will be able to call the same method from your screen rendering method (overridden System.Windows.Forms.Control.OnPaint or your handler of the event System.Windows.Forms.Control.Paint), with the printer's instance of Graphics when using PrintDocument, with the bitmap instance of Graphics when writing drawing on a bitmap, for example, to provide export of graphics to a bitmap, and elsewhere.

—SA
 
Share this answer
 
v2

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