title: How to pop up camera using picture box when button click?
body: <p>I make a program in C# windows form I have tons of function in my form including two datagrid view that connected to dabase and including a camera that direcly connected to my PC I use AForge dll reference to connect to the camera device I just found the tutorial on <a href="http://www.youtube.com/watch?v=j4tAbB258wc" rel="nofollow noreferrer">youtube</a> and it works perfecly for me, as I stated earlier I have too many programs in one form including that camera and it went out that the camera was need to be resized to a small resolution, so I decided to make a popup button that must show the wider resolution when I click the button on my form.</p>
  
  <p>this is the code for my camera.</p>
  
  <pre><code>    //Camera
  
      // get the devices name
      private void getCamList()
      {
          try
          {
              videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
              comboBox1.Items.Clear();
              if (videoDevices.Count == 0)
                  throw new ApplicationException();
  
              DeviceExist = true;
              foreach (FilterInfo device in videoDevices)
              {
                  comboBox1.Items.Add(device.Name);
              }
              comboBox1.SelectedIndex = 0; //make dafault to first cam
          }
          catch (ApplicationException)
          {
              DeviceExist = false;
              comboBox1.Items.Add("No capture device on your system");
          }
      }
  
      //refresh button
      private void refresh_Click(object sender, EventArgs e)
      {
          getCamList();
      }
  
      //toggle start and stop button
      private void start_Click(object sender, EventArgs e)
      {
          if (start.Text == "&amp;Start")
          {
              if (DeviceExist)
              {
                  videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
                  videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
                  CloseVideoSource();
                  videoSource.DesiredFrameSize = new Size(160, 120);
                  //videoSource.DesiredFrameRate = 10;
                  videoSource.Start();
                  lblCam.Text = "Device running...";
                  start.Text = "&amp;Stop";
              }
              else
              {
                  lblCam.Text = "Error: No Device selected.";
              }
          }
          else
          {
              if (videoSource.IsRunning)
              {
                  CloseVideoSource();
                  lblCam.Text = "Device stopped.";
                  start.Text = "&amp;Start";
              }
          }
      }
  
      //eventhandler if new frame is ready
      private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
      {
          Bitmap img = (Bitmap)eventArgs.Frame.Clone();
          //do processing here
          pictureBox1.Image = img;
      }
  
      //close the device safely
      private void CloseVideoSource()
      {
          if (!(videoSource == null))
              if (videoSource.IsRunning)
              {
                  videoSource.SignalToStop();
                  videoSource = null;
              }
      }
  
      //prevent sudden close while device is running
      private void Form1_FormClosed(object sender, FormClosingEventArgs e)
      {
          CloseVideoSource();
      }
  
  
  } }
  </code></pre>
  
  <p>I also posted a picture so that you have further understanding what I am talking.
  <img src="https://i.stack.imgur.com/OLjkP.png" alt="enter image description here">
  as you can see at the lower right corner I have a pop up button there honestly telling you I already tried different methods but nothing works unfotunately I cannot post what I've tried because I created it yesterday and can no longer undo the codes I tried. Any Idea? </p>