【发布时间】:2014-10-06 04:00:39
【问题描述】:
在我的VB.NET 项目子表单的InitializeComponents() 中添加以下代码后:
Skybound.Gecko.Xpcom.Initialize(Application.StartupPath & "\SuperGecko\xulrunner-1.9.1.11.en-US.win32\xulrunner")
Gecko.GeckoPreferences.User("security.warn_viewing_mixed") = False
Gecko.GeckoPreferences.User("plugin.state.flash") = 0
当我尝试从 MDI 父窗体打开此子窗体时出现此错误:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
如果我从InitializeComponents() 中删除代码,打开表单时会弹出另一个错误:
Couldn't not find XULRunner in myxulrunnerpath
但路径是正确的,我尝试将该代码放在 Form_Load 事件上,但它仍然不起作用。
可能是什么原因?
【问题讨论】:
-
你为什么要向
InitializeComponent方法添加代码?该方法由 Windows 窗体设计器生成并重新生成。如果您想将代码添加到表单的初始化中,则将其放入构造函数中,在调用InitializeComponent之后,或在Load事件处理程序中。 -
在 C# 中,在
Form_Load之前有一个对InitializeComponent();的调用,但是在 VB.NET 中我可以在哪里找到对InitializeComponent的调用? -
在 C# 中,构造函数中有一个对
InitializeComponent的调用,它在 VB 中的位置完全相同。不同之处在于默认构造函数在 VB 中是隐式的。如果您想向构造函数添加代码,则只需键入Public Sub New()并按 Enter。 IDE 将完成该方法,包括对InitializeComponent的调用。 -
@jmcilhinney 谢谢你。我会试试看它是否能解决我的问题。