新表单上的WebBrowser控件 [英] WebBrowser Control on new form

查看:86
本文介绍了新表单上的WebBrowser控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个带datagridview的Windows窗体应用程序,当用户单击gridview时,将打开一个新窗体并在其上带有webbrowser控件,它将浏览到存储在gridview上的URL,第二种形式被称为.

调用表单的主应用程序上的代码是:

Form2 F2 =新的Form2(url);
F2.Show();

url是要传递给webbrowser控件的地址.

在Form2上,我创建了webbrowser控件并获取url并尝试导航到它,但是我遇到了以下异常:

无法实例化"ActiveX控件" 8856f961-340a-11d0-a96b-00c04fd705a2",因为当前线程不在单线程单元中."

任何帮助将不胜感激!

Hello, I have a windows form app with a datagridview, when the user clicks on the gridview a new form is to be opened with a webbrowser control on it wich will browse to an url that is stored on the gridview from where the second form was called.

The code on the main app that calls the form is:

Form2 F2 = new Form2(url);
F2.Show();

Where the url is the address that is going to be passed to the webbrowser control.

On Form2 I create the webbrowser control and get the url and try to navigate to it however I''m getting this exception:

"ActiveX control ''8856f961-340a-11d0-a96b-00c04fd705a2'' cannot be instantiated because the current thread us not in a single-threaded apartment."

Any help will be appreciated!

推荐答案

错误是自我记录.您的应用程序必须是单线程的.也不应该使用显示来显示在本地创建的表单,因为它会失去与它的所有连接.
The error is self documenting. Your app needs to be single threaded. You should also never use Show to show a form that is created locally, as you lose all connection to it.


这篇关于新表单上的WebBrowser控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆