C #: What is the correct way to show the form for "frmMainForm" settings and disposal?
Splash screen: There are two forms: the main application form and a form for editing various settings for the main application operations.
How would one show the frmSettings form and how to delete it after clicking OK or Cancel in a real frmSettings form?
Perhaps a Dialog is a better fit for your Preferences form. There are subtle differences between dialogue and form that would make dialogue easier to handle. A return code indicating the button that was clicked makes dialog boxes useful.
Suppose you used a dialog - the using statement (from the top of the head) can be used:
using (DialogSettings dlgSettings = new DialogSettings)
{
if (dlgSettings.ShowDialog() == DialogResult.OK)
{
}
}
If you insist on using a form, you have to
- Enter the form
- show form
- record if ok or cancel was clicked to navigate to the form level variable (from form code ok / cancel button click)
- hide form
- save the recorded value from the form
- delete the form
- use saved value ok / cancel
fyi, using "frm" is not a recommended part of the C # coding rules. Microsoft prefers that you don't use Hungarian notation in .NET at all .
using (frmSettings s = new frmSettings() )
{
if( s.ShowDialog() == DialogResult.OK )
{
//do work
}
}
In the main application, declare an instance and show it.
using(frmSettings settingsInstance = new frmSettings())
{
settingsInstance.Show(); //or ShowDialog()
}
Then just close the form when you're done ...