WindowsFormsApplicationBase.Startup 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於應用程式啟動時。
public:
event Microsoft::VisualBasic::ApplicationServices::StartupEventHandler ^ Startup;
public event Microsoft.VisualBasic.ApplicationServices.StartupEventHandler Startup;
member this.Startup : Microsoft.VisualBasic.ApplicationServices.StartupEventHandler
Public Custom Event Startup As StartupEventHandler
Public Event Startup As StartupEventHandler
事件類型
範例
這個範例會 My.Application.SplashScreen
使用 屬性和 My.Application.Startup
事件,以應用程式啟動時的狀態資訊來更新啟動顯示畫面。
Private Sub MyApplication_Startup(
sender As Object,
e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs
) Handles Me.Startup
' Get the splash screen.
Dim splash As SplashScreen1 = CType(My.Application.SplashScreen, SplashScreen1)
' Display current status information.
splash.Status = "Current user: " & My.User.Name
End Sub
此範例要求專案具有名為 的 SplashScreen1
啟動顯示畫面。 啟動顯示畫面必須有名為 Status
的屬性,才能更新其使用者介面。
您必須在應用程式事件的 [程式代碼 編輯器] 視窗中輸入程式代碼。 若要存取此視窗,請遵循本主題的一節中的指示。 如需詳細資訊,請參閱 Application Page, Project Designer (Visual Basic)。
備註
一般 (非單一實例) 應用程式會在每次啟動時引發 Startup
事件。 單一實例應用程式 Startup
只有在應用程式尚未使用時才會啟動事件,否則會引發 StartupNextInstance
事件。 如需詳細資訊,請參閱StartupNextInstance。
此事件是 Visual Basic 應用程式模型的一部分。 如需詳細資訊,請參閱 Visual Basic應用程式模型概觀。
您可以使用 Cancel 參數的 e
屬性來控制應用程式的啟動表單載入。 當屬性 Cancel 設定為 True
時,啟動表單不會啟動。 在此情況下,您的程式代碼應該呼叫替代的啟動程式代碼路徑。
您可以使用 CommandLine 參數的 e
屬性或 CommandLineArgs 屬性來存取應用程式的命令行自變數。
事件處理程式的程式 Startup
代碼會儲存在預設隱藏的 ApplicationEvents.vb 檔案中。
存取應用程式事件的 [程序代碼 編輯器] 視窗 |
1.在 方案總管 中選取專案時,單擊 [專案] 功能表上的 [屬性]。 2. 按一下 [應用程式]索引標籤。 3.按兩下 [檢視應用程式事件] 按鈕,以開啟程式代碼 編輯器。 如需詳細資訊,請參閱 Application Page, Project Designer (Visual Basic)。 |
依專案類型的可用性
專案類型 | 可用 |
---|---|
Windows Forms 應用程式 | 是 |
類別庫 | 否 |
主控台應用程式 | 否 |
Windows Form 控制項程式庫 | 否 |
Web 控制項程式庫 | 否 |
Windows 服務 | 否 |
網站 | 否 |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應