VB.NET:加载表单并将其隐藏 [英] VB.NET: Load form and hide it
问题描述
我的项目中有一个表格.此表单仅用于向其他应用程序(例如,外部ActiveX-exe)发出信号,表明我的应用程序仍在运行.
I have a form in my project. This form is only there to signalize to other application (for example external ActiveX-exes) that my application is still alive.
我以主要形式这样声明:
I have declared it like this in the main form:
Private m_fVirtualContainer As frmVirtualContainer
现在,当我实例化它时,我会说:
Now when I instantiate it, I say:
m_fVirtualContainer = New frmVirtualContainer
但是,这不会触发表单的加载"事件.
However, this does not trigger the form's "Load" event.
我必须添加 m_fVirtualContainer.Show()
I have to add m_fVirtualContainer.Show()
...触发Load事件.
... to trigger the Load event.
在表单中,我有以下子内容:
In the form I have the following sub:
Private Sub frmVirtualContainer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Visible = False
End Sub
但是我认为并希望这是一个过大的杀伤力. 我只想加载表单,而不显示它.
But I think and hope that this is an overkill. I only want to load the form, not show it.
有人可以告诉我该怎么做吗? 谢谢!
Can somebody please tell me how to do that? Thank you!
推荐答案
向项目添加一个新模块,它将作为项目的启动对象.
Add a new module to project, this will act as the startup object for the project.
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
这篇关于VB.NET:加载表单并将其隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!