2014-02-18 59 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