How do I re-Load a Form?

mechwarrior3

Well-known member
Joined
Dec 19, 2005
Messages
67
Programming Experience
Beginner
So my project involves a "New" button. This button when clicked pops up a message box that asks if I'd like to save the current information before continuing on. It is a YesNoCancel message box. When I click Yes or No, I need the form to be re-loaded back to all of its default values. How can I use my Form1_Load method to do this? Actually, can I even do this? All help and suggestions are greatly appreciated. :)
 
You have these methods for forms and controls...


ResetBackColor (inherited from Control)Resets the BackColor property to its default value.
ResetBindings (inherited from Control)Resets the DataBindings property to its default value.
ResetCursor (inherited from Control)Resets the Cursor property to its default value.
ResetFont (inherited from Control)Resets the Font property to its default value.
ResetForeColor (inherited from Control)Resets the ForeColor property to its default value.
ResetImeMode (inherited from Control)Resets the ImeMode property to its default value.
ResetRightToLeft (inherited from Control)Resets the RightToLeft property to its default value.
ResetText (inherited from Control)Resets the Text property to its default value.

If you just wanted to reset all Text properties for instance:
VB.NET:
me.resettext
for each ctl in me.controls
ctl.resettext
next
 
So is there no way that I can make a call to the Form1_Load method to take care of reseting all the values I'd like to reset?
 
do you set the values you want to restore in your form1_load sub?
 
Yes. My Form1_Load Sub takes care of all of the setting of certain values because I need some controls to be displayed a certain way at the beginning.

My Form1_Load Sub has those input parameters like sender as object and e as eventargs. How do I try to force those values so I can make a call to my Form1_Load Sub?

Or can I not do that and so I should instead make several subroutines that handle all of my initial value settings and just call them from my Form1_Load Subroutine?
 
In my perception of object oriented programming you should make a separate sub for your "loads" and call this sub from form_load event handler and every other method that needs to do "loads". You *can* call form_load event handler without it being initiated from a real form load event, but that would be "breaking the rules" and makes code more unreadable.
If you still want to do this because you are lazy and don't care about rules and programming model you can call it like this:
form1_load(me,new eventargs)
 
Hahaha. Okay. Thanks, John. I'll make a whole bunch of subroutines instead. I don't like breaking the rules. ;) Thank you for your help. :)
 
Or simply write a subroutine with all the settings you have in the load sub routine in it. Then call that routine in the load or any other time you want it.

Example
Form1_Load ....

DefaultSettings()
End sub


Private Sub DefaultSettings()
... set all the controls here...
End sub

Now you can call DefaultSettings anytime in your code and reset the property's. This isn't breaking the rules and is more of what you should do. In reality anytime you run code that not directly partaining the event your in you should have a seperate routine for it. So thousands of routines would be better than posting tons of code in event handlers. also seperate modules and classes named and or in namespaces with the type of code your writing would be cleaner also. Try to make code in your form call only sub procedures and you will get better at this and understand how much more flexible it becomes...

For example... in your form.. every thing you want to do if it requires more than one line of code make a sub for it and call it. This will make stronger code and build modules/classes related to your topics that can be used with many forms.
 
well, that was exactly my suggestion, too ;)
JohnH said:
...you should make a separate sub for your "loads" and call this sub from form_load event handler and every other method that needs to do "loads".
 
Well, if that was your suggestion then that's not breaking the rules that's useing it how it was meant to be. And you wording may have thrown it off a lil b/c I was lost a lil with it too. And as always, if you can, code examples even in Pseudo makes a huge difference.
 
"breaking the rules" was the other option, the one you seemed so keen to do, and to which you were given a code example.
JohnH said:
You *can* call form_load event handler without it being initiated from a real form load event, but that would be...
 
Well, at first, I had only made a bunch of different sub routines. Now, I have only one sub routine in my Form load event. This one sub routine now calls all of those other bunches of sub routines. It's a mix of both your ideas and I really appreciate both your help with this. :)
 
Back
Top