Wednesday, 15 June 2011

Select and display Image files from ListBox, to be display within PictureBox? C# -



Select and display Image files from ListBox, to be display within PictureBox? C# -

i trying create listbox (lstfiles) selectable, it's able display image file within picturebox (picturebox1) , alter after selecting file listbox, im creating webcam programme takes pictures works, having problem with displaying images.

i have tried many ways can't work selecting filename listbox

any help grateful give thanks you

this have far:

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.drawing.imaging; using system.runtime.interopservices; using system.text; using system.windows.forms; using pinvoke; using system.io; namespace testavicap32 { public partial class form1 : form { public form1() { initializecomponent(); initializedeviceslist(); } private void initializedeviceslist() { splitcontainer1.panel1.enabled = true; splitcontainer1.panel2.enabled = false; foreach (capturedevice device in capturedevice.getdevices()) { cbodevices.items.add(device); } if (cbodevices.items.count > 0) { cbodevices.selectedindex = 0; } } private void btnstart_click(object sender, eventargs e) { int index = cbodevices.selectedindex; if (index != -1) { splitcontainer1.panel1.enabled = false; splitcontainer1.panel2.enabled = true; ((capturedevice)cbodevices.selecteditem).attach(pbimage); } } private void btnstop_click(object sender, eventargs e) { splitcontainer1.panel1.enabled = true; splitcontainer1.panel2.enabled = false; ((capturedevice)cbodevices.selecteditem).detach(); } private void btnsnapshot_click(object sender, eventargs e) { seek { image image = ((capturedevice)cbodevices.selecteditem).capture(); image.save(@"c:\webcapture\" + datetime.now.tostring("hh.mm.ss-dd-mm-yy") + ".png", imageformat.png); } grab (exception ex) { messagebox.show(ex.tostring(), "error", messageboxbuttons.ok, messageboxicon.error); } } private void btntimer_click(object sender, eventargs e) { timer1.enabled = true; btntimerstop.visible = true; btntimer.visible = false; } private void timer1_tick(object sender, eventargs e) { image image = ((capturedevice)cbodevices.selecteditem).capture(); image.save(@"c:\webcapture\" + datetime.now.tostring("hh.mm.ss-dd-mm-yy") + ".png", imageformat.png); } private void btntimerstop_click(object sender, eventargs e) { timer1.enabled = false; btntimer.visible = true; btntimerstop.visible = false; } private void form1_load(object sender, eventargs e) { btntimerstop.visible = false; foreach (driveinfo di in driveinfo.getdrives()) lstdrive.items.add(di); } private void lstfolders_selectedindexchanged(object sender, eventargs e) { lstfiles.items.clear(); directoryinfo dir = (directoryinfo)lstfolders.selecteditem; foreach (fileinfo fi in dir.getfiles()) lstfiles.items.add(fi); } private void lstdrive_selectedindexchanged(object sender, eventargs e) { lstfolders.items.clear(); seek { driveinfo drive = (driveinfo)lstdrive.selecteditem; foreach (directoryinfo dirinfo in drive.rootdirectory.getdirectories()) lstfolders.items.add(dirinfo); } grab (exception ex) { messagebox.show(ex.message); } } private void lstfiles_selectedindexchanged(object sender, eventargs e) { } private void picturebox1_click(object sender, eventargs e) { } private void openfiledialog1_fileok(object sender, canceleventargs e) { //i don't know if need this? } } }

try below... work....

private void lstfiles_selectedindexchanged(object sender, eventargs e) { picturebox1.image = image.fromfile(((fileinfo)lstfiles.selecteditem).fullname); }

c# listbox picturebox

No comments:

Post a Comment