What is the equivalent of Program.cs in VB.NET WinForms application?
I need to move my .CS app to VB.NET.
As I do not have forms in my WinForms project in Program.cs I do the following:
Application.Run(new MyForm(parm1, parm2);
How to move this code in VB.NET?
Thanks
Program.cs is the entry Point for application. Like any application the execution of Application starts from public static void Main(string[] args){} This Program. cs creates the application Host. It configures the setiings file like appsettings.
If your program code is already in a Visual Studio project, open the project. To do so, you can double-click or tap on the . csproj file in Windows File Explorer, or choose Open a project in Visual Studio, browse to find the . csproj file, and select the file.
ASP.NET Core apps created with the web templates contain the application startup code in the Program. cs file. The Program. cs file is where: Services required by the app are configured.
cs you just add a method there, you need to make it static since the Program class is static . To call it from a button, just double click the button in the designer and an event handler is created. The same principle applies if you put the code in another file.
By default, VB.NET applications use the mysterious Windows Application Framework which means that the build process adds an entry point for you which automatically runs whichever form you use as the main form. You can access these settings via Project Properties > Application > Windows application framework properties.
If you don't want to use the framework, un-check the Enable application framework check box and then select that you want to use Sub Main
as your Startup object. Then you can create a module with a Public Sub Main
method which will be the entry point to the application, just like in Program.cs in C#.
It doesn't matter whether it's Program.cs or YouNameIt.cs.
The default entry point is Main()
.
This code should work, unless you have another entry point (Can be specified in project settings).
Shared Sub Main()
' Starts the application.
Application.Run(New Form1())
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With