I am trying to show a form using Form.ShowDialog as shown below:
var f = new Form();
if(f.ShowDialog() == DialogResult.OK)
{
...
}
...
if(f.ShowDialog() == DialogResult.OK)
{
...
}
The issue is the OnHandleDestroyed is called once a dialog result is returned and the form is closed.
So the question is: Is it possible to use ShowDialog() without closing the form (and hiding it instead) OR to show a form modally using Show() and Hide()?
When you show a form using ShowDialog
, after closing the form DestroyHandle
will be called automatically.
To prevent the behavior you can override DestroyHandle
method and write your own logic.
Example
public class MyForm : Form
{
protected override void DestroyHandle()
{
if (!Modal || Disposing)
base.DestroyHandle();
}
}
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.