简体   繁体   English

从头开始创建图形并返回它们以打印页面事件

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

I'm working in C# .NET 3.5. 我在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... 我想在类中写一个“getprintobject”函数来返回绘制到我的打印文档上的东西,但是我很难过......

I wish I could just create and return a graphics object, but I don't see a "e.graphics.drawgraphics()". 我希望我可以创建并返回一个图形对象,但我没有看到“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. 我还想过创建一个位图或图像并返回它,但我不知道如何从头创建一个并获得一个新的图形对象来修改它。

Create an Image, and use that image as a base for your Graphics object. 创建一个图像,并将该图像用作Graphics对象的基础。 eg 例如

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. 在您的图形对象上绘图,将绘制您的图像 - 然后您可以返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM