0

Here i want to set the imagelocation like this:

pic1.ImageLocation = "";
pic2.ImageLocation = "";

and so on...

foreach (ImageResult result in response.Image.Results)
{
    i++;
    PictureBox thumnailBox = new System.Windows.Forms.PictureBox();
    thumnailBox.Name = "pic" + i.ToString();
    //HOW TO DO ??
    //thumnailBox.ImageLocation = result.Thumbnail.Url;
    //listView1.Items.Add(thumnailBox.Name);                     
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
jack
  • 3
  • 1
  • 2
  • What's the problem? Why doesn't `thumnailBox.ImageLocation = result.Thumbnail.Url;` work for you? – Cody Gray - on strike Mar 28 '11 at 06:26
  • Hi Cody Gray, I want to set the ImageLocation properties by its picturebox ID for example pic1.ImageLocation = "rose.jpg"; pic2.ImageLocation = "lily.jpg"; – jack Mar 28 '11 at 06:33
  • Does the image not show? Do you see an error? Did you debug the code and see what values for response.Image.Results you are getting? Are they valid URL's to the images? Your question is way too vague, @jack. – invert Mar 28 '11 at 08:18
  • @Wesley I have 10 different images and the image is shown but only 1 image is shown. I run the foreach loop to get all of my images and set the imagelocation path "thumnailBox.ImageLocation = result.Thumnail.Url" and add this thumnailBox control to listview1.Controls.Add(thumbnail); but this is showing me only 1 picture. I want to show all the picture in listview. I wish you understand my question – jack Mar 28 '11 at 12:29

2 Answers2

0

Your problem is you are likely creating all of your picture boxes on top of one another. You need to set the actual location of your PictureBoxes (and likely their sizes) in such a way that they don't completely or partially overlap one another.

This can be accomplished with the code thumbnailBox.Location = new Point(x,y); where x and y are ints.

As mentioned before, don't forget to change the thumbnailBox.Size as well.

Update: Another problem might be that you need to create an array of PictureBoxes, by doing:

PictureBox[] thumbnailBoxes = new PictureBox[numPics];

and iterate through those when setting their images and locations.

Then, outside your loop, you add the entire array to the Controls by doing Controls.AddRange(thumbnailBoxes);

Yetti
  • 1,710
  • 1
  • 14
  • 28
0

I see what you want to do, you want to show each image in the listview?

You need to add a imagelist control to store all the images, then you link each listview item to the stored image.

    // add imagelist and listview controls
    ImageList imglist = new ImageList( this.components);
    ListView lst = new ListView();
    lst.LargeImageList = imglist;
    this.Controls.Add(lst);

That sets up the controls you need. Then in your loop load the image into the imagelist, give it a key, and use that key in you list item:

    for (int i = 0; i < 0; i++)
    {
        imglist.images.add(image.fromfile("the-filename.jpg"));
        listviewitem itm = new listviewitem();
        string key = string.format("pic{0}", i);
        itm.text = key;
        itm.imagekey = key;
        lst.items.add(itm);
    }

This is pseudo code, of course it won't compile as is, but you get the idea?

invert
  • 2,016
  • 14
  • 20