Esempio n. 1
0
        /// <summary>
        /// Handler - Form load.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Config_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                // Refresh the list of available cameras
                cmbCameras.Items.Clear();
                foreach (Camera cam in _webCam.GetCameras())
                {
                    cmbCameras.Items.Add(cam);
                }

                // Find string value of last setting.  If not found, set it to index 0.
                int cmbIndex = 0;
                for (int i = 0; i < cmbCameras.Items.Count; i++)
                {
                    if (((Camera)cmbCameras.Items[i]).Name == _mainForm._settings.SelectedCameraDisplayName)
                    {
                        cmbIndex = i;
                    }
                }

                // Set combo box index. It will be the selected camera or zero.
                if (cmbCameras.Items.Count > 0)
                {
                    // Restore persisted camera.
                    cmbCameras.SelectedIndex = cmbIndex;
                    _webCam.SetCamera((Camera)cmbCameras.SelectedItem);

                    // If there was not persisted camera, then the cmbIndex will
                    //  be zero.  If the selected cmbIndex name doesn't match
                    //  the persisted one (it won't), set the flag to enable
                    //  user to save this "new" selection.
                    if (_mainForm._settings.SelectedCameraDisplayName
                        != ((Camera)cmbCameras.SelectedItem).Name)
                    {
                        // Save camera and dirty flag.
                        _mainForm._settings.SelectedCameraDisplayName = ((Camera)cmbCameras.SelectedItem).Name;
                        btnSaveSettings.Enabled = true;
                    }
                }

                timer.Enabled = true;
            }

            // Enable GUI events now that all is set up.
            cmbCameras.SelectedIndexChanged
                += new EventHandler(this.cmbCameras_SelectedIndexChanged);
        }
Esempio n. 2
0
        private void TakePicture_Load(object sender, EventArgs e)
        {
            // Make sure there is a persisted camera.
            if (String.IsNullOrEmpty(_mainForm._settings.SelectedCameraDisplayName))
            {
                MessageBox.Show("Error: No camera name has been saved.  "
                                + "Select one with the command line '/config' option.",
                                "No camera name saved");
                return;
            }

            // Select the persisted camera from the available ones.
            bool foundCamera = false;

            foreach (Camera cam in _webCam.GetCameras())
            {
                if (cam.Name == _mainForm._settings.SelectedCameraDisplayName)
                {
                    _webCam.SetCamera(cam);
                    foundCamera = true;
                    break;
                }
            }

            // Return error if couldn't find one.
            if (!foundCamera)
            {
                MessageBox.Show("Could not find camera: " + _mainForm._settings.SelectedCameraDisplayName,
                                "Camera not found");
                return;
            }

            _webCam.Stop();

            // Enable GUI events now that all is set up.


            _webCam.Start();
            _webCam.FlipImageHorizontally(_mainForm._settings.FlipImageHorizontally);
        }