c# - Switching images in picturebox -
in windows forms application have display few (or more) images in 1 picturebox - need change every 10 seconds (or similar).
first retrieve images database , display them in specific picturebox.
every image has unique id , 1 image works fine.
i have sql database (sql server 2014) , use linq.
public void displayadds(imagead img, int imgid) { using (var dbcontext = new linqclassesdatacontext()) { var table = t in dbcontext.imageads t.id == imgid select t; img.image = table.single().image; picturebox1.image = bytearraytoimage(img.image.toarray()); } }
in end 'displaying' has in foreach loop, because have list of ints (list), display images selected ids.
i tried using threads, or refreshing, , simple loop didn't work:
for(int i=0; i<5; i++) { displayadds(img, i); }
here other methods tried , didn't work.
public void displayad(imagead img) { int = 1; using (var dbcontext = new linqclassesdatacontext()) { while (true) { var table = t in dbcontext.imageads t.id == select t; img.image = table.single().image; picturebox1.image = bytearraytoimage(img.image.toarray()); thread.sleep(1000); i++; if (i >= 15) = 1; } } } public void displaylist(imagead img) { using (var dbcontext = new linqclassesdatacontext()) { (int = 0; < 5; i++) { var table = t in dbcontext.imageads t.id == select t; img.image = table.single().image; // picturebox1.image = bytearraytoimage(img.image.toarray()); picturebox pb = new picturebox(); //254,15 pb.location = new point(254, 15); pb.size = new size(310, 367); // pb.borderstyle = borderstyle.fixed3d; pb.image = bytearraytoimage(img.image.toarray()); pb.cursor = system.windows.forms.cursors.hand; this.controls.add(pb); pb.bringtofront(); thread.sleep(1000); } } }
i found way far works fine. turned out on stackoverflow , unfortunately hadn't found earlier: changing image in picture box rapidly
and used this:
var table = t in dbcontext.imageads t.id == select t; img.image = table.single().image; picturebox1.image = bytearraytoimage(img.image.toarray()); picturebox1.refresh(); await task.delay(1000);
Comments
Post a Comment