简体   繁体   English

C#WinForms等待表单继续

[英]C# WinForms Wait on form to proceed

I'm tired and hungry, so I might of missed it, but from what I can see no existing post covers this... 我又累又饿,所以我可能会想念它,但是从我看来,没有现有的文章涵盖这件事...

I'm writing a plugin for an application. 我正在为应用程序编写插件。 My plugin loads a form to get some data specifically, it uses the webcam to scan for a barcode. 我的插件加载了一个表单来专门获取一些数据,它使用网络摄像头扫描条形码。 Once it's found a barcode, the form hides itself (incase it's needed again later). 一旦找到条形码,表单就会隐藏起来(以防以后再次需要)。 This is how I currently call the form that does the barcode work: 这是我目前如何调用条形码工作形式的方式:

string readData = null;

if (eye == null)
{
    System.Windows.Forms.Application.EnableVisualStyles();
    eye = new CamView();
}
eye.Show();
if (eye.found)
{
    readData = eye.readData;
}

return readData;

So, my problem is that eye.show() doesn't block. 所以,我的问题是eye.show()不会阻塞。 It makes the form appear and carries right on before there's a chance for the barcode to appear. 它使表格出现并继续进行,直到有机会出现条形码。 I imagine I need to use some form of threading or locking, but my crude attempts to do so have just frozen the interface completely. 我想我需要使用某种形式的线程或锁定,但是我的粗鲁尝试只是完全冻结了接口。

The "eye" form is basically just a viewfinder for the webcam, and relies on the camera_OnImageCapture event to make it do it's image checks for the barcode. “眼睛”形式基本上只是网络摄像头的取景器,它依靠camera_OnImageCapture事件来进行条形码的图像检查。

Is there an elegant way to make the application calling the plugin wait for the form to finish? 有没有一种优雅的方法可以使调用插件的应用程序等待表单完成? Or do I just need to add an accept button to the "eye form?" 还是只需要在“眼睛表格”中添加一个接受按钮?

Cheers. 干杯。 And humble apologies if this is in anyway a repost. 如果这仍然是转贴,请对此致以歉意。

.ShowDialog(); .ShowDialog(); http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx

"You can use this method to display a modal dialog box in your application. When this method is called, the code following it is not executed until after the dialog box is closed. " “您可以使用此方法在您的应用程序中显示一个模式对话框。调用此方法时, 直到关闭对话框后该代码才执行。

You are on the right track. 您走在正确的轨道上。 You change the code to show CamView as a modal dialog but do no add an Accept button. 您更改代码以将CamView显示为模式对话框,但不添加“接受”按钮。 Instead change camera_OnImageCapture to close the dialog. 而是更改camera_OnImageCapture以关闭对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM