[RESOLVED] VB.Net and Sub Main()
Hey, this is just a throw out to all the techies here in the forums. I do most of my coding in C#, but I do answer a lot of questions in VB.Net and recently I find myself increasingly frustrated by the lack of an exposed Program class in VB.Net Windows Forms Applications.
The reason I find this irritating is mainly in the case of questions about user validation. As i'm sure many of you already know and do, the best practice for user validation is not to run the program at all unless the user has been validated.
Hypothetically, in a VB.Net application, the Sub Main() would probably look something like this:
Code:
Module Program
Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Dim success As Boolean
Using login As New LoginForm
success = (login.ShowDialog() = Windows.Forms.DialogResult.OK)
End Using
If success Then _
Application.Run(New MainForm())
End Sub
End Class
Unfortunately, unlike in C#, i've been completely unable to expose Sub Main() in VB.Net. Have any of you managed, or heard of a way to expose or override this sub in VB.Net?
Re: VB.Net and Sub Main()
What version of VS are you using?
If you are using VS2008, look into the Application Events object. You can expose this by clicking the View Application Events button on the Application tab of the project properties.
From here you can access the startup & shutdown events of the application, among others.
Re: VB.Net and Sub Main()
In VB.NET you have to turn off the Application Framework in the project properties to be able to create your own Main method as an entry point. The thing is, you really shouldn't because that's one of the reasons that the Application Framework exists. Follow the WinForms Logon link in my signature to see how it's done in VB.
Re: VB.Net and Sub Main()