本文介绍了Visual Studio Winforms 项目隐藏启动代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 中创建 VB.NET Winforms 项目时,有很多与初始化相关的代码似乎被隐藏了.有没有办法展示它,通过创建MyProjectMyApplication 对象,创建和展示SplashScreen 最后定义和创建My.Application.ApplicationContext.MainForm?

When creating a VB.NET Winforms Project in Visual Studio, there's a lot of code related to initialization that seems to be hidden. Is there a way to show it in order to see which statements run from the very beginning, through creation of MyProject and MyApplication objects, creation and exhibition of SplashScreen and finally definition and creation of My.Application.ApplicationContext.MainForm?

也就是说,Console 应用程序项目有一个可见的 Sub Main(),我认为 Winforms 应用程序也应该有一个,但它是隐藏的,并且包含为以下项目创建实例的例程SplashScreen、主窗体等.我想更好地看到和理解这个流程.

That is, a Console application project has a Sub Main() that is visible, I presume a Winforms Application should have one too, but it is hidden and packed with the routines that create instances for SplashScreen, main Form and etc. I would like to see and understand better this flow.

谢谢!

推荐答案

点击项目 -->属性 -->应用程序选项卡 -->查看应用程序事件按钮(选项卡的右下角).

Click on Project --> Properties --> Application Tab --> View Application Events Button (bottom right of the tab).

在这里您可以创建一个 Application.Startup() 事件,相当于控制台应用程序中的Sub Main;至少它是您应该放置需要运行的代码的第一个位置.*使用代码编辑器顶部的下拉菜单;更改我的应用程序"到(MyApplication Events)",并将OnCreateMainForm"更改为到启动".

Here you can create an Application.Startup() Event, which is equivalent to Sub Main in a Console Application; at least it's the first place you should place code that needs to run. *Use the DropDowns across the top of the code editor; change "MyApplication" to "(MyApplication Events)", and change "OnCreateMainForm" to "Startup".

这里还可以查看构造函数New()OnCreateMainForm(),这是创建启动表单的地方.以下是所有这些的示例:

Here you can also view the Constructor New() and OnCreateMainForm(), which is where the startup form is created. Below is an example of all these together:

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

这篇关于Visual Studio Winforms 项目隐藏启动代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:15