c# - Display 4 picturebox 1 by 1 -


so have button , 4 pictureboxes , when click button want add on first picturebox 1 picture , if click button second time want make picturebox2 = picturebox1 , picturebox1 = new image , on until 4 did far it's not working, shows me on 4 pictureboxes same image:

namespace imageuploadandcamerause {     public partial class form1 : form     {         image file;         image file2;         image file3;         image file4;          bool button1click = true;         bool button1click2 = true;         bool button1click3 = true;         bool button1click4 = true;          public form1()         {             initializecomponent();         }          private void button1_click(object sender, eventargs e)         {             openfiledialog f = new openfiledialog();             f.filter = "image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";              bool isnullorempty1 = false;             bool isnullorempty2 = false;             bool isnullorempty3 = false;              if (f.showdialog() == dialogresult.ok)             {                 if (button1click)                 {                     file = image.fromfile(f.filename);                     picturebox1.image = file;                      isnullorempty1 = true;                     button1click = false;                 }                 if (isnullorempty1 && button1click2 )                 {                     file2 = image.fromfile(f.filename);                     picturebox2.image = picturebox1.image;                     picturebox1.image = file2;                      isnullorempty2 = true;                     button1click2 = false;                 }                 if (isnullorempty2 && button1click3)                 {                     file3 = image.fromfile(f.filename);                     picturebox3.image = file3;                     isnullorempty3 = true;                     button1click3 = false;                 }                 if (isnullorempty3 && button1click4)                 {                     file4 = image.fromfile(f.filename);                     picturebox4.image = file4;                     button1click4 = false;                 }             }         }     } } 

and if know: how can make program use device camera take photo if dont have in picturebox / folder create store these photos.

you can loop through pictureboxes accomplish this:

int boxindex = 0;  private void button1_click(object sender, eventargs e) {   openfiledialog f = new openfiledialog();   f.filter = "image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";   if (f.showdialog() == dialogresult.ok) {     picturebox[] boxes = new picturebox[] { picturebox1, picturebox2, picturebox3, picturebox4 };     if (boxindex + 1 > boxes.length) {       foreach (picturebox pb in boxes) {         pb.image = null;       }       boxindex = 0;     }     (int = boxindex; > 0; --i) {       boxes[i].image = boxes[i - 1].image;     }     boxes[0].image = image.fromfile(f.filename);     boxindex++;   } } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -