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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21866280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:49:27  来源:igfitidea点击:

VB.NET: Load form and hide it

vb.netforms

提问by tmighty

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.

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

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.

但是,这不会触发表单的“加载”事件。

I have to add m_fVirtualContainer.Show()

我必须添加 m_fVirtualContainer.Show()

... to trigger the Load event.

... 触发 Load 事件。

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!

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

回答by jhayton

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