2014-02-18 48 views
0

我在我的项目中有一个窗体。此表单仅用于向其他应用程序(例如外部ActiveX-exes)指示我的应用程序仍然存在。VB.NET:加载表单并隐藏它

我已经在主要形式宣布它是这样的:

Private m_fVirtualContainer As frmVirtualContainer 

现在,当我实例化,我说:

m_fVirtualContainer = New frmVirtualContainer 

不过,这并不会触发窗体的“加载”事件。

我要补充 m_fVirtualContainer.Show()

...触发Load事件。

在我有以下子形式:

Private Sub frmVirtualContainer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    Me.Visible = False 

End Sub 

但我认为并希望这是矫枉过正。 我只想加载表单,而不是显示它。

有人可以告诉我该怎么做吗? 谢谢!

+1

为什么不把你需要的代码放在窗体的构造函数中?我不认为你可以从加载中取消表单的实际显示。 Load()仅在Form.Show()afaik上调用。 – Brandon

+0

你的意思是? – tmighty

+0

其实,我想你可以破解它..看到这个链接。 http://stackoverflow.com/questions/11148671/cancel-form-load – Brandon

回答

0

将新模块添加到项目中,这将作为项目的启动对象。

Sub Main() 
' Instantiate a new instance of Form1. 
Dim f1 as New Form1() 
' Display a messagebox. This shows the application is running, 
' yet there is nothing shown to the user. This is the point at 
' which you customize your form. 
System.Windows.Forms.MessageBox.Show("The application is running now, but no forms have been shown.") 
' Customize the form. 
f1.Text = "Running Form" 
' Show the instance of the form modally. 
f1.ShowDialog() 
End Sub 
+0

我不想再使用“Sub Main”,但感谢您的建议。 – tmighty