// Constructor public VideoCaptureDeviceForm( ) { InitializeComponent( ); // show device list try { // enumerate video devices videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice ); if ( videoDevices.Count == 0 ) throw new ApplicationException( ); // add all devices to combo foreach ( FilterInfo device in videoDevices ) { devicesCombo.Items.Add( device.Name ); } } catch ( ApplicationException ) { devicesCombo.Items.Add( "No local capture devices" ); devicesCombo.Enabled = false; okButton.Enabled = false; } devicesCombo.SelectedIndex = 0; }
public MainForm() { InitializeComponent(); camera1FpsLabel.Text = string.Empty; camera2FpsLabel.Text = string.Empty; // show device list try { // enumerate video devices videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { throw new Exception(); } for (int i = 1, n = videoDevices.Count; i <= n; i++) { string cameraName = i + " : " + videoDevices[i - 1].Name; camera1Combo.Items.Add(cameraName); camera2Combo.Items.Add(cameraName); } // check cameras count if (videoDevices.Count == 1) { camera2Combo.Items.Clear(); camera2Combo.Items.Add("Only one camera found"); camera2Combo.SelectedIndex = 0; camera2Combo.Enabled = false; } else { camera2Combo.SelectedIndex = 1; } camera1Combo.SelectedIndex = 0; } catch { startButton.Enabled = false; camera1Combo.Items.Add("No cameras found"); camera2Combo.Items.Add("No cameras found"); camera1Combo.SelectedIndex = 0; camera2Combo.SelectedIndex = 0; camera1Combo.Enabled = false; camera2Combo.Enabled = false; } }
// Main form is loaded private void MainForm_Load( object sender, EventArgs e ) { // enumerate video devices videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice ); if ( videoDevices.Count != 0 ) { // add all devices to combo foreach ( FilterInfo device in videoDevices ) { devicesCombo.Items.Add( device.Name ); } } else { devicesCombo.Items.Add( "No DirectShow devices found" ); } devicesCombo.SelectedIndex = 0; EnableConnectionControls( true ); }