我在主窗体的按钮中有一个函数,单击时启动相机,我希望该启动函数也以第二种形式执行,该函数包含条件语句 if 和 else。通常我会创建一个public void Name
并将函数放入其中,然后我会以第二种形式创建一个构造函数来调用该函数,但这次它不起作用。你怎么做另一种方式?
public void startProg()
{
if (start.Text == "&Start")
{
if (DeviceExist)
{
videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
CloseVideoSource();
videoSource.DesiredFrameSize = new Size(1366, 768);
//videoSource.DesiredFrameRate = 10;
videoSource.Start();
lblCam.Text = "Device running...";
start.Text = "&Stop";
}
else
{
lblCam.Text = "Error: No Device selected.";
}
}
else
{
if (videoSource.IsRunning)
{
CloseVideoSource();
lblCam.Text = "Device stopped.";
start.Text = "&Start";
}
}
}
private void start_Click(object sender, EventArgs e)
{
startProg();
}
第二种形式
private void Close(object sender, FormClosingEventArgs e)
{
frmMain main = new frmMain();
main.startProg();
}