在一页中打印多个图像 [英] Print multiple images in one page
问题描述
嗯,我想要实现的是打印预制的图片,使它们在一个页面中全部组合在一起(实际上这页只有4张图片)
所以它应该看起来像一个Word文档,但在C#中这一次
预览: https:// i。 imgur.com/BpRQvqT.jpg [ ^ ] < br $> b $ b
我不知道这样做的正确方法是什么,我想到了一个DataGridView或tableLayoutPanel但是无法做到这一点
所以任何帮助将不胜感激
*注意:这是一个新项目,欢迎所有各种方法
请参阅我对该问题的评论。任何方法都可以解决问题,我甚至无法想象如何失败它。所以,让我来描述一下最简单的方法。使用类System.Drawing.PictureBox
(我几乎总是不鼓励使用它,因为我们的查询者倾向于滥用它来解决更复杂的问题,然后这个简单的控件被设计用于,但你的情况恰恰相反,太简单了):
https://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox%28v=vs.110%29.aspx [ ^ ]。
创建4个实例,在每个实例中放入适当的图像(https://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image(v = vs.110).aspx [ ^ ]),调整每个控件的尺寸
和位置
实现你的布局。
Sherif Kamel
嗯,我觉得你错了。我的意思是我想在一张纸上打印它,并在问题中包含预览。所以问题在于从应用程序到打印机的转换过程。好吧,抱歉没有得到它。
当你使用System.Drawing.Printing.PrintDocument
,您需要使用其PrintPage
事件。在这种情况下,您必须直接渲染图形: https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.110%29.aspx [ ^ ]。
您的布局将归结为对System.Drawing.Graphics.DrawImage
的调用,其中包含适当的参数(位置,大小,等等。
此外,我建议你抽象出渲染方法,使用相同的方法进行屏幕,打印页面,打印预览,任何其他媒体。创建一个类似Render(System.Drawing.Graphics)
的方法,并从不同媒体的渲染句柄中调用它,重用它。不,在这种情况下,不要使用PictureBox
。
参见:https://msdn.microsoft.com/en-us/library /system.drawing.graphics.drawimage%28v=vs.110%29.aspx [ ^ ]。
-SA
Well, what I'd like to achieve is to print pre-made pictures so that they all fit all-together in one page (actually there will only be 4 pictures in this page)
so it should look like a Word document, but in C# this time
preview : https://i.imgur.com/BpRQvqT.jpg[^]
Well I don't know what's the right way to do so , I thought about a DataGridView or tableLayoutPanel but couldn't do it right
so any help would be appreciated
*Note: this is a new project, so all various methods are welcomed
Please see my comment to the question. Any method would do the trick, and I cannot even imagine how it would be possible to fail it. So, let me describe just on of the simplest possible approaches. Use the classSystem.Drawing.PictureBox
(which I almost always discourage to use, because our inquirers tend to abuse it to solve more complicated problems then this simple control is designed for, but you case is the opposite, too simple):
https://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox%28v=vs.110%29.aspx[^].
Create 4 instances, put an appropriate image in each (https://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image(v=vs.110).aspx[^]), adjustSize
andLocation
of each control to implement your layout.
[EDIT]
Sherif Kamel
Well I think you got me wrong on that. What I meant is that I want to PRINT it on a paper with the preview included in the question. So the problem rely in the conversion process from the application to the printer.Well, sorry for not getting it.
When you useSystem.Drawing.Printing.PrintDocument
, you will need to use itsPrintPage
event. In this event, you have to render graphics directly: https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.110%29.aspx[^].
You layout will boil down to the calls toSystem.Drawing.Graphics.DrawImage
with appropriate parameters (location, size, and so on).
Moreover, I would advise you to abstract out the rendering method, to have the same method for screen, print page, print preview, any other media. Create a method likeRender(System.Drawing.Graphics)
and call it from your rendering handles for different media, reuse it. And no, in this case, don't usePictureBox
.
See also: https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110%29.aspx[^].
—SA
这篇关于在一页中打印多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!