Click here to Skip to main content
15,173,340 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
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
Posted
Comments
   
You need to specify (tag) System.Windows.Forms.
I have no idea what prevented you from rendering images like that. Perhaps you did something wrong, but you did not show any code, so I have no idea what's wrong. It could be DataGridView, yes, or you can use PictureBox instances (per image), or you can render images directly on any custom control or even Panel. The problem is not just simple, it's extremely simple, so I don't even know what needs any explanations. Just arrange images the way you want, that's it.
—SA
BillWoodruff 20-Dec-15 3:37am
   
Is this Windows Forms ?

Do you wish to move, or re-size, the PictureBoxes at run-time.

Are the pictures all the same size ?
Sherif Kamel 22-Dec-15 13:10pm
   
@BillWoodruff yes it's WinForms, and yes all the 4 pictures will always be the same size
Member 12229636 26-Dec-15 13:09pm
   
Nice ques and solution is given. Even I was facing the same problem. Thanks :)
mobile application development company india

1 solution

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 class System.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[^]), adjust Size and Location 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 use System.Drawing.Printing.PrintDocument, you will need to use its PrintPage 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 to System.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 like Render(System.Drawing.Graphics) and call it from your rendering handles for different media, reuse it. And no, in this case, don't use PictureBox.

See also: https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110%29.aspx[^].

—SA
   
v3
Comments
Sherif Kamel 22-Dec-15 13:09pm
   
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
Sergey Alexandrovich Kryukov 22-Dec-15 13:42pm
   
Sorry for not getting it. Please see the updated answer, after [EDIT].
—SA
Sherif Kamel 22-Dec-15 17:16pm
   
Followed these guidlines and I've a sample code now that works perfectly , I'll try to learn more to improve it later on. Thanks for the help sir :)
Sergey Alexandrovich Kryukov 22-Dec-15 17:18pm
   
It's such a pleasure to help someone who really does the job and makes things happen.
You are very welcome.
Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900