VB.NET:加载表单并隐藏它

时间:2014-02-18 21:54:21

标签: vb.net forms

我的项目中有一个表单。此表单仅用于向其他应用程序(例如外部ActiveX-exes)发出信号,表明我的应用程序仍处于活动状态。

我在主要形式中声明了这个:

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 个答案:

答案 0 :(得分:1)

向项目添加一个新模块,这将作为项目的启动对象。

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