Simple question. I have a MainForm and a settingsForm. The settings form is initialized once and then shown every time the user clicks a button. I need it to do something when this button is clicked.
m_inputSettings.ShowDialog(this); //edit settings selected, so show that form
This is the MainForm calling the settings form, which it does fine. But I need the SettingsForm to do something every time this happens. Presently, I cant figure out if this call actually triggers any events I can set handlers for. Does it trigger an event? If not, is there another way I can tell my SettingsForm to do something every time this call happens?
Note: Any code in the mainform after that line doesn't get executed until the SettingsForm returns, but that is intentional.
Thanks.
Edit: One of the things I want my form to do it select a specific control when this happens, but it seems that that is impossible until after the form is done loading everything.
FormShown
event - raised only once when form is displayed first time.
OnPaint / OnActivate
- every time form is activated, but these events raised even when you switch with other application, which probably you don't want to do.
If you are changing form visbility, then you can use OnVisibleChanged
If you are minimizing the form, you can use OnSizeChanged
/ OnLocationChanged
event.
If none suits you, make a public property and set false when form is closed / hidded, and set true before showing it. OnActivate
, use this property to do your task.
Override OnShown() event in your form this will raise only once after the form is opened The disadvantage of OnVisibleChanged is it will also get raised when the form is closed. On Paint , On Activate and OnEnter will raise before form is shown to the user.
You can override the OnVisibleChanged method in your settings form. Make sure to call base.OnVisibleChanged
though as to not screw up any potential observers of the event (and anything else the base class may do inside of that method.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With