private void btn_cam_Click(object sender, EventArgs e)
 {
     if (btn_cam.Text == "Open")
     {
         captureDevice.VideoResolution = videoCapabilitie;
         AVPlayer_Cam1.VideoSource     = captureDevice;
         if (ckBox_DeSwitch.Checked)
         {
             captureDevice.NewFrame += new NewFrameEventHandler(FaceDetection);
             btn_takePic.Enabled     = false;
         }
         else
         {
             btn_takePic.Enabled = true;
         }
         ckBox_DeSwitch.Enabled = false;
         captureDevice.SimulateTrigger();
         AVPlayer_Cam1.Start();
         btn_cam.Text = "Close";
     }
     else
     {
         if (ckBox_DeSwitch.Checked)
         {
             captureDevice.NewFrame -= new NewFrameEventHandler(FaceDetection);
         }
         ckBox_DeSwitch.Enabled = true;
         pBox_faceDst.Image     = null;
         AVPlayer_Cam1.Stop();
         AVPlayer_Cam1.VideoSource = null;
         btn_cam.Text = "Open";
     }
 }
 private void AForgeCamera_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (captureDevice != null)
     {
         captureDevice.Stop();
     }
     CaptureDevices.Clear();
     AVPlayer_Cam1.VideoSource = null;
     AVPlayer_Cam1.Stop();
 }