點擊Project - > Properties - > Application Tab - > View Application Events Button(選項卡的右下角)。
在這裏您可以創建一個Application.Startup() Event,這相當於在控制檯應用程序中的Sub Main
;至少它是您應該放置需要運行的代碼的第一個地方。 *使用代碼編輯器頂部的DropDown;將「MyApplication」更改爲「(MyApplication Events)」,並將「OnCreateMainForm」更改爲「Startup」。
這裏您還可以查看構造函數New()
和OnCreateMainForm()
,這是創建啓動窗體的地方。下面是所有這些共同的例子:
Option Strict On
Option Explicit On
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make changes,
' or if you encounter build errors in this file, go to the Project Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()>
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = False
Me.EnableVisualStyles = True
Me.SaveMySettingsOnExit = True
Me.ShutdownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()>
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.VB_Scratch_WinForms.Form1
End Sub
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
End Sub
End Class
End Namespace
如果你指的是形式初始化,然後在** Solution Explorer中的右上角**點擊按鈕與左邊三個文件** <> **然後單擊表單的小箭頭並打開** Form.Designer.vb ** – Mederic
@Mederic,不,我的意思是整個應用程序。也就是說,一個控制檯應用程序項目有一個可見的「Sub Main()」,我認爲Winforms應用程序也應該有一個,但它隱藏起來,並且爲創建SplashScreen,主窗體等實例而封裝。希望看到並更好地理解這個流程。 – VBobCat