Start up module for VB.NET Windows Application??
-
In VB6 i used to start my project from a Sub Main() which resided in a module. This codei n sub main then initialised many things and called various forms, ie splash screen and so on. However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other). I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this. Many Thanks
-
In VB6 i used to start my project from a Sub Main() which resided in a module. This codei n sub main then initialised many things and called various forms, ie splash screen and so on. However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other). I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this. Many Thanks
Every Class has a constructor and If you don't create one .NET will create one for you. As form is also a Class so it has its own Constructor it calls whenever we create an object of it so the best place to initialize things is the Constructor and in VB.NET its name is 'New' you can find the Constructor of your form inside 'Windows Form Generated Code'. For Example:
Sub New
'Initialize Code here
End Sub
Hope it helps !
AliAmjad(MCP) First make it Run THEN make it Run Fast!
-
Every Class has a constructor and If you don't create one .NET will create one for you. As form is also a Class so it has its own Constructor it calls whenever we create an object of it so the best place to initialize things is the Constructor and in VB.NET its name is 'New' you can find the Constructor of your form inside 'Windows Form Generated Code'. For Example:
Sub New
'Initialize Code here
End Sub
Hope it helps !
AliAmjad(MCP) First make it Run THEN make it Run Fast!
I'm having difficulty finding the windows generated code. I can see the code from the forms designer but that does not contain the constructor.
-
In VB6 i used to start my project from a Sub Main() which resided in a module. This codei n sub main then initialised many things and called various forms, ie splash screen and so on. However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other). I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this. Many Thanks
first create a Start up module I alway call it mMain and than create the Main() sub. than from the project menu select properties then from the application tab select the startup object as sub Main() in sub Main you should put the following code at the end: Application.EnableVisualStyles() Application.DoEvents() Application.Run(MainFrm)
-
I'm having difficulty finding the windows generated code. I can see the code from the forms designer but that does not contain the constructor.
When you click on the '+' sign besides "Windows Form Designer generated code" means when you expand it you'll see the code e.g.
Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call 'Your code goes here.... End Sub
I think you should buy a book because It'll really help you to clear your concepts ! hope it helps !
AliAmjad(MCP) First make it Run THEN make it Run Fast!
-
first create a Start up module I alway call it mMain and than create the Main() sub. than from the project menu select properties then from the application tab select the startup object as sub Main() in sub Main you should put the following code at the end: Application.EnableVisualStyles() Application.DoEvents() Application.Run(MainFrm)
When i uncheck the 'Enable application framework' though what implication does this have?
-
When you click on the '+' sign besides "Windows Form Designer generated code" means when you expand it you'll see the code e.g.
Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call 'Your code goes here.... End Sub
I think you should buy a book because It'll really help you to clear your concepts ! hope it helps !
AliAmjad(MCP) First make it Run THEN make it Run Fast!
AliAmjad Thanks, i do have a book and have seen the code you mention before. But for some reason it is not in my current form. When i select 'show all files' im the solution explorer, a plus sign appears next to my form which, if expanded, show me a Form.Designer.vb file and a Form.resx file. I can see some code with 'Mybase.Disposing' in the Form.Designer.vb file but cannot find the form constructor anywhere. I can create a constructor, with the same code as your comment and the IDE doesn't complain, but i would like to know why it is'nt there in the first place. I have also tried adding in another form, just in case the code was accidentily deleted but this was the same.