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:
void Render(System.Drawing.Graphics graphics, Rectangle drawingArea ) {
}
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