Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 can use to handle command-line parameters, etc...

However, when I create an equivalent project for VB, the application type is Windows Forms Application and I'm forced to pick a startup form.

Is there an equivalent mechanism to run my own code before I decide which form to display in VB.Net? I'm assuming the same code exists but is auto-generated and hidden somewhere? If so, where?

like image 484
Basic Avatar asked Jan 13 '13 18:01

Basic


People also ask

What is the entry point of VB net program?

What is entry point method of VB.NET program? Public Sub Main() indicates the entry point of VB.Net program.

Which is the main window in Visual Basic?

The Main window is the main way to access other windows, load and save files, control trajectory playback, change various global program settings, access help, and to quit the program. Many of these actions can also be performed with the menu shortcut keys described in Table 5.3.

How do I choose which form opens first in Visual Basic?

To set the startup form in Windows Forms: In Solution Explorer , right-click the project and choose Properties . The Project property page opens with the General properties displayed. Choose the form you want as the startup form from the Startup Object drop-down list.

Where does the name of application appear in VB net?

At the top of the form there is a title bar which displays the forms title. Form1 is the default name, you can change the name to your convenience . The title bar also includes the control box, which holds the minimize, maximize, and close buttons.


1 Answers

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

like image 186
Dom Sinclair Avatar answered Oct 01 '22 18:10

Dom Sinclair