Click here to Skip to main content
15,943,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

I am using VB.Net, VS2008 and Win7.
I want to add multiple images in one picturebox using VB.Net and display on printpreviewcontrol for print.
How can display multiple image in print preview control.

Help will be very apprecited.
Any link or idea my give me.

mukesh :-)
Updated 19-Mar-21 18:24pm

You can't show multiple images in a single PictureBox - it only has a single Image property.
To do something like this, you would have to create a large enough Bitmap object to hold your multiple images, and then draw them in, using a Graphics object from the Bitmap:
Using g As Graphics = Graphics.FromImage(myBigBitmap)
	For Each i As Image In myListOfImagesToAdd
		g.DrawImage(i, pointToDrawit)
		pointToDrawIt = MoveForNextImage(pointToDrawIt, i)
End Using

Presumably this will also solve your print preview problem, although I would strongly suggest you use a PrintDocument rather than try to print screen images...
Share this answer
Sergey Alexandrovich Kryukov 8-Jul-11 4:37am    
Agree, my 5. Good point about PrintDocument. See some more information in my answer, referenced.
Espen Harlinn 8-Jul-11 7:08am    
Good reply, my 5
OriginalGriff 27-Jul-13 9:01am    
What part do you not understand?
There is nothing particularly complex in that code, so I need to know what you don't know (if you see what I mean) :laugh:
fjdiewornncalwe 8-Jul-11 7:57am    
Just what I was thinking. +5.
You can't. A picture box is useless for anything except showing one image for people who don't know how to show one themselves. One box per picture, you can get around this by drawing all your pictures in to one big one and showing that, or by having many boxes, or by handing your paint event and drawing your own pics.
Share this answer
Sergey Alexandrovich Kryukov 8-Jul-11 4:38am    
Correct, my 5. Yet another variant of PictureBox (which is good almost for nothing) abuse. More detail in my answer.
Espen Harlinn 8-Jul-11 7:14am    
I would have expected a somewhat different answer from you Christian :)
Oh (sigh)… I discovered yet another case of an attempt to misuse of PictureBox. Let me explain that. This control is designed for somebody who does not want to deal with any graphics at all. Something simple and simpler. Nothing dynamic, animated, combined, manipulated. Pure static image, maybe sometimes replaced, but not often.

By the reason of deep confusion about graphics, many try to do a lot more, which is possible but just silly. This control does not help it, only presents a hassle.

So, what do to? Something way more simple:
How do I clear a panel from old drawing[^].

If you picture is static, it's even simpler than that. Do invalidation, no double buffering. But you can do moving images, animation, saving to file or loading from files and a lot more.

Share this answer
Christian Graus 8-Jul-11 4:38am    
Picture box was designed like a lot of MS stuff. So people too dumb to write code, can make things happen on the screen.
Sergey Alexandrovich Kryukov 8-Jul-11 8:22am    
Good point.
Espen Harlinn 8-Jul-11 7:13am    
Good points, my 5
Sergey Alexandrovich Kryukov 8-Jul-11 8:23am    
Thank you, Espen.
Take a look at Christian Graus' articles[^] about GDI+. That should help you do just about anything you would want to do - using the approach outlined by OriginalGriff.

Best regards
Espen Harlinn
Share this answer
Sergey Alexandrovich Kryukov 10-Jul-11 1:08am    
Another possible way to learn things on the topic. My 5.
Espen Harlinn 10-Jul-11 6:52am    
Thank you, Sergey! Christian has written a lot material that OP should find useful.

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