• 0

C# closing and reopening the same form


Question

7 answers to this question

Recommended Posts

  • 0

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

  • 0
  On 27/09/2013 at 04:09, Asik said:

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.

  • 0

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.

  • 0
  On 28/09/2013 at 12:19, firey said:

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.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.