C# WinForms 等待表单继续
我又累又饿,所以我可能会错过它,但从我看来,没有现有的帖子涵盖了这一点......
我正在为应用程序编写一个插件。我的插件加载一个表单来专门获取一些数据,它使用网络摄像头扫描条形码。一旦找到条形码,表单就会隐藏起来(以防以后再次需要)。这就是我目前调用条形码工作的表单的方式:
string readData = null;
if (eye == null)
{
System.Windows.Forms.Application.EnableVisualStyles();
eye = new CamView();
}
eye.Show();
if (eye.found)
{
readData = eye.readData;
}
return readData;
所以,我的问题是 eye.show() 不会阻塞。它使表格出现并在条形码有机会出现之前继续进行。我想我需要使用某种形式的线程或锁定,但我的粗暴尝试只是完全冻结了界面。
“眼睛”形式基本上只是网络摄像头的取景器,并依赖于camera_OnImageCapture 事件来使其对条形码进行图像检查。
有没有一种优雅的方法可以让调用插件的应用程序等待表单完成?或者我只需要在“眼睛表单”中添加一个接受按钮?
干杯。如果这是转发的话,我深表歉意。
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. 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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.ShowDialog();
http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx
“您可以使用此方法在应用程序中显示模式对话框。调用此方法时,直到对话框关闭后才会执行其后面的代码。”
.ShowDialog();
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."
你走在正确的轨道上。您更改代码以将 CamView 显示为模式对话框,但不添加“接受”按钮。相反,更改camera_OnImageCapture 以关闭对话框。
You are on the right track. You change the code to show CamView as a modal dialog but do no add an Accept button. Instead change camera_OnImageCapture to close the dialog.