1

I am working on winform application where I need to display a popup. I am currently doing it with ShowDialog() method. but due to change in requirement, I want to show it as non-dialog. So I have used show() method instead of showDialog().

my popup window is using windows webBrowse control as one of its child control.

my problem is when I use showDialog() method, everthing works fine. but when I use show() method, and close the popup (once user is done with his work), show method() somehow calling dispose method of webBrowse control and this is preventing me to relaunch same popup again and giving me "Cannot access a disposed object" error.

Is this expected behavior in show() method or webBrowse control. if yes, then how Can I resolve it.

Note: PopUp dialog box is injected in presenter using DI so cannot inject popup after every dispose.

Thanks in advance.

Abhash786
  • 881
  • 2
  • 24
  • 53

3 Answers3

0

By using showdialog() you can not go back to your parent form, by simply using show() you can go back, that's all

Ahsan Alii
  • 153
  • 1
  • 16
0

With Show(), your code proceeds to the line after the Show statement. With ShowDialog(), it does not.

Hari Prasad
  • 16,716
  • 4
  • 21
  • 35
0

You could try using Hide()instead of Close().

Put this in the constructor of your dialog window (this is a WPF example)

public Window()
{
    this.Closing += Window_Closing;
}

And then cancel the close event and hide the window instead like this

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = true;
    this.Hide();
}

After that you should be able to reopen a closed window, beacuse it's not disposed but hidden. Problem with this is, that you have to manually clean the content of the window before reopening it, because otherwiese it contains the conten of the last use.

schlonzo
  • 1,409
  • 13
  • 16