Sign in to follow this  
Followers 0
Kalint

C# closing and reopening the same form

8 posts in this topic

        private void ReOpen()
        {
            Hide();
            var reopen = new FrmPlaceItem();
            reopen.ShowDialog();
            Dispose();
        }

Soooo....  when I call this method, is it actually closing the current form and reopening a new one; or is the previous form still hidden :/

Share this post


Link to post
Share on other sites

Hiding the form does not close it. To close the form, call Close() (you don't need to call Dispose()). 

 

ShowDialog() is a blocking call that doesn't return until the dialog is closed. If you call Close() after calling ShowDialog() on the new form, the current form won't close until the dialog is closed. Avoid using ShowDialog() unless you actually want a modal window.

 

It doesn't make any sense to try to show a modal window after closing the parent window (hence why your code can't work). Not sure what you're trying to achieve...

Share this post


Link to post
Share on other sites

Hiding the form does not close it. To close the form, call Close() (you don't need to call Dispose()). 

 

ShowDialog() is a blocking call that doesn't return until the dialog is closed. If you call Close() after calling ShowDialog() on the new form, the current form won't close until the dialog is closed. Avoid using ShowDialog() unless you actually want a modal window.

 

It doesn't make any sense to try to show a modal window after closing the parent window (hence why your code can't work). Not sure what you're trying to achieve...

I have an excel add-in and when someone clicks "Place and Next" its to do its operation, move down a row in excel, and reopen the same form again.

Share this post


Link to post
Share on other sites

Basically in order to do something like that.. you would have something like:
 

private void openChildWindow()
{
     MyChildForm childForm = new MyChildForm();
     childForm.ShowDialog();
}

then you just have an event every cell click like, or during your "Pick and Next" you would call the function.
 

private void Cell_Click(Object sender, EventArgs e)
{
     openChildWindow();
}

It doesn't make sense to open an instance of a child form inside of the child form.  You need a parent to control that.

Share this post


Link to post
Share on other sites

Basically in order to do something like that.. you would have something like:

 

private void openChildWindow()
{
     MyChildForm childForm = new MyChildForm();
     childForm.ShowDialog();
}

then you just have an event every cell click like, or during your "Pick and Next" you would call the function.

 

private void Cell_Click(Object sender, EventArgs e)
{
     openChildWindow();
}

It doesn't make sense to open an instance of a child form inside of the child form.  You need a parent to control that.

Ah well that explanation makes much more sense.

Share this post


Link to post
Share on other sites

Ah well that explanation makes much more sense.

You get it all figured out?

Share this post


Link to post
Share on other sites

You get it all figured out?

Yes I have, thanks!

Share this post


Link to post
Share on other sites

Yes I have, thanks!

Awesome :D no problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.