How to find the main() entry point in a VB.Net winforms app?

后端 未结 2 1598
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 23:34

When I create a WinForms app in C#, the output type is Windows Application and I get a program.cs with a static void Main() which I ca

相关标签:
2条回答
  • 2020-12-05 23:48

    If your application has only one form you may simply start typing Sub New() and Visual Studio will autogenerate this method stub which executes first. No project setting changes required.

    Public Sub New()
        MyBase.New()
    
        'This call is required by the Windows Form Designer.
        InitializeComponent()
    
        'Add any initialization after the InitializeComponent() call
        '==> Put your pre-execution steps here.
    End Sub
    
    0 讨论(0)
  • 2020-12-06 00:00

    In VB you'll need to create your sub main by hand as it were so what I generally do is create a new Module named Program.

    Within that as a very basic setup you'll need to add the following code.

    Public Sub Main()
    
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        Application.Run(New Form1)
    
    End Sub
    

    Once you've done that go to the application tab of the project's settings and uncheck the 'Enable Application framework' setting and then from the drop down under Startup object select your new Sub Main procedure.

    You can then put any start-up code that you want to run before your program opens its main form before the Application.Run line.

    Hope that helps

    0 讨论(0)
提交回复
热议问题