display multiple images on a windows form in C#

Hi,

If I have to load a few images (lets say from 5 to 10) on a windows form from database, whats the best way to do it? use dynamically generated pictureboxes? I should be able to drag images around, something like google picasa...  I can load them to an imageList but I'm trying to get more ideas about displaying them..

Has anyone done anything similar?

LVL 3
prajeebkumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Here is a class to convert between a byte array and images:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

public class MemoryImage
{

  public Image ByteArrayToImage(byte[] buffer, string fileName)
  {
    MemoryStream ms = new MemoryStream(buffer);
    Image img = Image.FromStream(ms);
    return img;
  }

  public byte[] ImageToByteArray(Image img, ImageFormat format)
  {
    MemoryStream ms = new MemoryStream();
    img.Save(ms, format);
    return ms.ToArray();
  }
}

Bob
prajeebkumarAuthor Commented:
Hi,

thank you for the reply. But I'm actually looking for suggestions on how to display the images on the form, like google picasa may be.. assume I have an image array that contains images.. now what is the best way to load them on the windows form, using picture boxes or something else?  i'm not very familiar with windows programming, so if thats what you mentioned above, plz explain a little more.
Bob LearnedCommented:
I haven't used Picasa, so how does it display the images?  You can easily use PictureBox controls to display images.

Bob
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

prajeebkumarAuthor Commented:
I'm not sure how picasa display the images on the panel.. they have lot of images arranged side by side which you can move around on form..  i know I can use picture boxes to display images but i'm wondering if thats the best way. I wouldn't know how many images are there beforehand so I have to programatically create pictureboxes on the fly.. also, is that the only control that can be used to display images on windows forms?  

btw, if you have lot of photo albums on your pc, you should probably download picasa, its free and really nice to arrange albums, just fyi!
Bob LearnedCommented:
If you want to tile images across a page, then you could do something like this.

int x = 20;
int y = 20;
int maxHeight = -1

foreach (Image img in this.ImageCollection)
{
   PictureBox pic = new PictureBox();
   pic.Image = img;
   pic.Location = new Point(x, y);

   x += pic.Width + 10;
   maxHeight = Math.Max(pic.Height, maxHeight);

   if (x > this.ClientSize.Width - 100)
   {
      x = 20;
      y += maxHeight + 10;
   }
}

Bob
prajeebkumarAuthor Commented:
Hi,

thats a nice suggestion. Please go to the following question and post a reply so I can assign points to you for that.
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21817805.html

I would still like to keep this question open to see if anybody else has any other ideas. I'm surprised picture box is the only control you can display images on windows programming.
Bob LearnedCommented:
Points for questions are not allowed anymore.  You can display images in other controls, but it is a bit more difficult.  

Bob
prajeebkumarAuthor Commented:
you mean, i cannot create another question to assign points to you?
Bob LearnedCommented:
Nope.  It against the membership guidelines to create a condition where the points go above 500.  I don't need the points anyway.

Let's get this question answered.

Bob
prajeebkumarAuthor Commented:
ok, I created another question for you anyway. If you would like, I can assign you points if you reply to this question,
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21817805.html  .. you just need to post something so I can assign points, its upto you.

Thank you for your help, I'm just keeping it open just to see if someone has another idea. I will try your solution first and see if that achieves what I need to do.

Bob LearnedCommented:
1) You can add images to an ImageList control, and then display them in a ListView control.

2) If a control has a Paint event, such as a Panel, you can always use GDI+ to draw an image on the control.

Bob

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prajeebkumarAuthor Commented:
do you have a sample code for the second idea you mentioned? drawing image on a panel? if not, dont worry about it, I'll look it up..

thanks for your suggestions. I guess I'm going to assign the points to you for all your help. I could be back if I need more help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.