Reputation: 83
i found this code on github. when u type someting it will search on google and show first image to u in picturebox1 - now i want to add 3-4 other picture box and i want it to show other pictures as well (like second and third - not just the first one ). my problem is i can't understand how to do it.
try {
this.Cursor = Cursors.WaitCursor;
this._lblStatus.Text = "Searching...";
this._lblStatus.Update();
List<String> images_urls = t.SearchForImages (this._editImageText.Text.Trim());
if (t.Error == null && images_urls.Count > 0) {
//Show first image only
foreach (String image_url in images_urls) {
Bitmap bitmap = ImageUtil.LoadPicture(image_url);
if (bitmap != null) { //sometime the server refuses getting the image directly
Image image = ImageUtil.ResizeImage(bitmap, pictureBox1, true);
pictureBox1.Image = image;
if (bitmap != null) bitmap.Dispose();
break; //show only one image
What I have tried: i deleted the break; but it just keep searching and it never stop. i want it to be like other sites ( for ex: show 5-10 pic in every page ). what should i change ? what am i doing wrong ?
Upvotes: 5
Views: 2615
Reputation:
Besides deleting the break from the loop, take the first 5 images only
foreach (String image_url in images_urls.Take(5)) {
The above filter is done by a Linq method, of course you can change the number.
I guess you don't want to use pictureBox1 also for the other images: you can create the PictureBox controls with a new
in the foreach loop and add them to the Controls collection
Upvotes: 2