c# – 当用户从窗口栏/ etc关闭它时,是一个表单

前端之家收集整理的这篇文章主要介绍了c# – 当用户从窗口栏/ etc关闭它时,是一个表单前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
用户用右上角的X或Alt F4关闭它时,System. Windows.Forms.Form是否自动处理?窗体显示为form.Show(this),而不是form.ShowDialog(…);

解决方法

有了Show,是的(在WmClose的结尾).使用ShowDialog,不行.乐趣; –

对于ShowDialog,see MSDN

Because a form displayed as a dialog Box is not closed,you must call the Dispose method of the form when the form is no longer needed by your application.

为了证明这一点:

Form main = new Form();
Form test = new Form();
test.Text = "Close me";
test.Disposed += delegate {
    main.Text = "Second form was disposed";
};
main.Shown += delegate {
    test.Show();
};
Application.Run(main);

猜你在找的C#相关文章