using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;namespace _718单个摄像头
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            btnPlay.Enabled = false;
            btnStop.Enabled = true;
            btnPz.Enabled = true;
            video = new cVideo(pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height);
            video.StartWebCam();
        }
        //在【关闭视频】按钮的Click事件中添加如下代码:
        private void b_stop_Click(object sender, EventArgs e)
        {
            btnPlay.Enabled = true;
            btnStop.Enabled = false;
            btnPz.Enabled = false;
            video.CloseWebcam();
        }
        //在【拍摄照片】按钮的Click事件下添加如下代码:
        private void btnPz_Click(object sender, EventArgs e)
        {
            video.GrabImage(pictureBox1.Handle, "d:\\a.bmp");
        }
    }
}

解决方案 »

  1.   

    可能在整个程序范围内,定义有一个cVideo的实例对象video。你在IDE里,在你红字的这几个video上点鼠标右链,转到定义,就能找到它在哪里声明的了。
      

  2.   

    //在最外面定义,并且保证要先按button1,否则会说“未将对象引用到实例”
    cVideo video; 
    private void button1_Click(object sender, EventArgs e)
      {
      btnPlay.Enabled = false;
      btnStop.Enabled = true;
      btnPz.Enabled = true;
      video = new cVideo(pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height);
      video.StartWebCam();
      }
      

  3.   

    cVideo video = null;
    public Form1()
      {
      InitializeComponent();
      }