简体   繁体   中英

what is the difference between show and showdialog in term of form closing in c#.net

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.

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.

通过使用 showdialog() 你不能回到你的父窗体,通过简单地使用 show() 你可以返回,就是这样

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM