-
Mar 17th, 2025, 01:01 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Where is VB Net Startup code so I can initialze items on the GUI?
I don't see any place, or file, which has a location for me to place any initialization code for my GUI/Program. The only files available are as seen in the screenshot. So what file did I not get from the loader, or in what file do I place my code? I know in some forms I generated for experimental purposes there was a MyApplication page, but none in the Windows Forms App (Net).
Appreciate your advise.
Well..... Seems the drag drop/add files does not accept my picture.
So here is a list of available files.
Solution Items
- ClsBrowser
-ClsEPIQ
-ClsErrorLog
EPIQ Interface
-My Project
-References
-App.config
-Form1
Did the program get generated without a needed file? I have looked in all of the files for some sore of startup point and have not found one for initializing my items.
-
Mar 17th, 2025, 01:34 PM
#2
Re: Where is VB Net Startup code so I can initialze items on the GUI?
Follow these steps:
- From the menu bar, click on Project > {Project Name} Properties
- In the Application tab, click on View Application Events
- In the dropdowns at the top of the file, generate the Startup event
- Alternatively, just copy/paste this method:
Code:
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
End Sub
Anything that you put in the Startup event will fire when the application starts but before the startup form has been created.
Alternatively, if you want code to run anytime a form is initialized then you can use the constructor of the class:
Code:
Public Class Form1
Public Sub New()
' controls have not been created yet
InitializeComponent()
' controls have been created
End Sub
End Class
-
Mar 17th, 2025, 01:44 PM
#3
Thread Starter
Addicted Member
Re: Where is VB Net Startup code so I can initialze items on the GUI?
 Originally Posted by dday9
Follow these steps:
- From the menu bar, click on Project > {Project Name} Properties
- In the Application tab, click on View Application Events
- In the dropdowns at the top of the file, generate the Startup event
- Alternatively, just copy/paste this method:
Code:
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
End Sub
Anything that you put in the Startup event will fire when the application starts but before the startup form has been created.
Alternatively, if you want code to run anytime a form is initialized then you can use the constructor of the class:
Code:
Public Class Form1
Public Sub New()
' controls have not been created yet
InitializeComponent()
' controls have been created
End Sub
End Class
Thank you!
-
Mar 17th, 2025, 01:49 PM
#4
Thread Starter
Addicted Member
Re: Where is VB Net Startup code so I can initialze items on the GUI?
 Originally Posted by FunkMonkey
Thank you!
OK, another question. In the properties DLG box the configuration = N/A, Platform = N/A, and Configuration manager are all disabled. If I use your code method where would I put it? In the Form Class?
Well wasnt the last question stupid? Sorry. But what does Sub New() do for the issue?
Last edited by FunkMonkey; Mar 17th, 2025 at 01:55 PM.
-
Mar 17th, 2025, 02:12 PM
#5
Re: Where is VB Net Startup code so I can initialze items on the GUI?
 Originally Posted by FunkMonkey
OK, another question. In the properties DLG box the configuration = N/A, Platform = N/A, and Configuration manager are all disabled. If I use your code method where would I put it? In the Form Class?
The configuration and platform options are properties of the project and I don't think that they're accessible or changeable at runtime. Think of them as metadata that tells the compiler how it should behave. They appear disabled in the Application tab of the project's properties because they are managed at the solution level through the Configuration Manager via Build > Configuration Manager. But you're saying that the Configuration Manager is not accessible?
 Originally Posted by FunkMonkey
Well wasnt the last question stupid? Sorry. But what does Sub New() do for the issue?
It wasn't immediately obvious what you were trying to do in your original post, so I wanted to throw that out there in case it was useful. It doesn't sound like you even need the application's startup event either though.
-
Mar 17th, 2025, 03:29 PM
#6
Re: Where is VB Net Startup code so I can initialze items on the GUI?
Sub New is the constructor for the class. There is some advantage to that, because it is called at a different time from other code in a form.
Every form has a constructor. If you don't create one yourself, you will find one in the .designer.vb file associated with the form. It is best not to mess with that file unless you know what is in there, because the designer might overwrite any changes you make, or you might mess up the designer. Best to leave it alone, but it's good to take a look at, because it is just code like all other code. That's where the constructor is, the destructor, and it's where all the controls on the form are declared, created and set up.
The key about the constructor is that if you were to do this:
Code:
Dim nf As New MyForm
nf.ShowDialog
then the constructor runs on the New MyForm, but things like the Load event, and all subsequent events, only occur when ShowDialog is called. Since there is no particular need for you to show a form immediately after creating it (though that is the typical way to do things), you can use that to some advantage in some rare cases. Slow running things could be launched by putting them in the constructor and creating the form long before you actually need to show it. I've used that at times, but really only a few times, as it is a pretty rare scenario. Still, it's good to know about.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|