Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am working on an application in which there is one main form and several other forms that can be used concurrently. when A user clicks to open another form, I'd like to make it so that clicking the button for the form does not open the form up again if it is already open.

showDialog wont work because the user still needs to have access to the controls on the main form.

here is my code for the help window, all the other forms open the same way.

private void heToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form help = new help();
            help.Show();
        } 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
216 views
Welcome To Ask or Share your Answers For Others

1 Answer

Alternatively you can use the Application's open forms to see if it is open

btn_LaunchHelp(object o, EventArgs e)
{

   foreach (Form f in Application.OpenForms)
   {
       if (f is HelpForm)
       {
           f.Focus();
           return;
       }
   }

   new help().Show();
}

Edit: To be more clear, this allows the user to close the Help anytime and makes is much easier to manage than saving a reference to the Help window. Nothing to clean up, nothing to maintain.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...