Skip to content

How do I make sure only 1 child window opens?

spyder.snyper

spyder.snyper

Asked Feb 12, 2007, 1:16 PM EST1 answer
Share
LinkedInX
So... I've got a button on the Main window that opens up a child window. If you click on it multiple times, it opens up multiple windows. This is not a good thing for this app... SO... Is there an easy way to to the following:... When you click on the open button, it opens a new window. If the window is already open in another spot, it will either close that window and open a new one, or simply relocate the existing window and place it where it would open. Any siggestions???

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    There's possibly a better way to do this in c#, but the logic I'm thinking of here:

    a. Create the instance of the form as global to the class.
    b. On the button click, just call the object.Show().

    If you wanted the functionality to close any existing form, and then re-open a fresh one, you could check if the object is currently displayed, then close it, then open it again?

    Hence:

    class MyClass
    {
       MyForm myForm1 = new MyForm();

       void OnButtonClick()
       {
           // simple solution...
           myForm1.Show();
       }
    }

    Hope it helps.
    0