点击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