Steve Goykovich
Steve Goykovich

Reputation: 757

Creating graphics from scratch and returning them to print a page event

I'm working in C# .NET 3.5. I have a class of recipes that contains an image and some strings. I want to print out these recipes, four per page. I want to write a "getprintobject" function in the class to return something to draw onto my print document, but I'm stumped...

I wish I could just create and return a graphics object, but I don't see a "e.graphics.drawgraphics()". I have also thought about creating a bitmap or image and returning that, but I'm not sure how to create one from scratch and get a new graphics object to modify it.

Upvotes: 4

Views: 4858

Answers (1)

George Johnston
George Johnston

Reputation: 32258

Create an Image, and use that image as a base for your Graphics object. e.g.

Bitmap img = new Bitmap(50, 50);
Graphics g = Graphics.FromImage(img);

Drawing on your graphics object, will draw on your image -- which you can then return.

Upvotes: 8

Related Questions