Question How to executor code at program startup?

Chxnge4790

New member
Joined
Nov 24, 2020
Messages
2
Programming Experience
1-3
Hi :D
Can anyone help me, how do i execute a line of code when I launch my build/exe?
 
You really need to be far more specific than that. Please provide a FULL and CLEAR explanation of the problem. I would assume that you would already know how to execute code in an application so there must be something more specific at issue here so tell us EXACTLY what that is. Assume that too many words is better than not enough.
 
Okay, my bad for not explaining enough, I'm new to all this forum stuff. So basically in my program you can press a button and it will execute a line of code, but is there a way to auto execute/do a line of code, when I start my program, so it will do the same stuff the button does, but just automatically when the program starts?
 
Put that line of code at the beginning of your program. Recall that every C# program start out in Main(). So put that line of code somewhere there before the rest of your code runs.

Or most GUI frameworks like WPF and WinForms let you have custom code in the constructor for the class that represents the primary UI, you could put that line of code there. Those GUI frameworks also have events for when the UI is first shown or loaded. You could also put that line of code there.
 
Those GUI frameworks also have events for when the UI is first shown or loaded. You could also put that line of code there.
That's the recommended direction to go. You can use the .Shown Event to execute the code. This will wait until the form has loaded and execute your code when the form is first presented to the user. This is the desired event!

What project type is this? Winforms/WPF?
 

Latest posts

Back
Top Bottom