Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:54:32+00:00 2026-06-18T12:54:32+00:00

I am trying to make my listBox ( lstFiles ) selectable, so it’s able

  • 0

I am trying to make my listBox (lstFiles) selectable, so it’s able to display the image file within a pictureBox (pictureBox1) and change after selecting another file from listBox, Im creating a webcam program that takes pictures which works, but having trouble with with displaying the images.

I have tried many ways but can’t get it to work from selecting the filename from the listbox

Any help would be grateful thank you

This is what I have so 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)
        {
            try
            {
                Image image = ((CaptureDevice)cboDevices.SelectedItem).Capture();
                image.Save(@"c:\webcapture\" + DateTime.Now.ToString("HH.mm.ss-dd-MM-yy") + ".png", ImageFormat.Png);

            }
            catch (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();

            try
            {
                DriveInfo drive = (DriveInfo)lstDrive.SelectedItem;

                foreach (DirectoryInfo dirInfo in drive.RootDirectory.GetDirectories())
                    lstFolders.Items.Add(dirInfo);
            }
            catch (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 I need this?
        }

        }
   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:54:34+00:00Added an answer on June 18, 2026 at 12:54 pm

    Try like below… it will work….

    private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
    {
      pictureBox1.Image = Image.FromFile(((FileInfo)lstFiles.SelectedItem).FullName);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to change a listbox in my main form from another file (nodes.cs)
I am trying to make a long ListBox with each ListBoxItem being a tile
I'm trying to make a style for a listbox which will set the selected
I have a ListBox in a Silverlight Application. I'm trying to make an editable
I'm trying to make a ListBox that updates to the contents of an ObservableCollection
I'm trying to make a standard WPF listbox be dynamically filled, and for each
Working with a listbox in windows phone 7 I am trying to make an
i am trying to make a ListBox that contains a string at right side
I am trying to make my ASP:Listbox throw an event in javascript that will
i have a listbox and i am trying to make the scrolling work without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.