jmgardn2
jmgardn2

Reputation: 961

Copy Graphics variable to print Graphics variable

I'm using C#, and I have a Graphics variable (printImage), in that I add rectangles and strings to the printImage variable during form Load. In the Print Document PrintPage event I'd like to copy what is in the printImage Graphic into the Printing graphic. Either that or add to the Printing graphic itself during form load. Any ideas?

Upvotes: 0

Views: 356

Answers (1)

Hans Passant
Hans Passant

Reputation: 942020

You cannot add shapes to a variable of type Graphics. It is merely a class with methods that help you draw shapes. Only a Bitmap (or Image) can contain shapes. But that's pretty useless for printing, a printer has a much higher resolution than the screen.

You can use a GraphicsPath to do the equivalent of storing shapes. But the simplest way is to just have a private method that does all the drawing. Give it an argument of type Graphics. And call it both from your form's Paint event handler and your PrintPage event handler, passing e.Graphics as the argument.

Upvotes: 1

Related Questions