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?

0


source to share


4 answers


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
+3


source


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 .



+1


source


using (frmSettings s = new frmSettings() )
{
   if( s.ShowDialog() == DialogResult.OK )
   {
       //do work
   }
}

      

0


source


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 ...

0


source







All Articles