单击X按钮将关闭所有实例化的表单. [英] X button click closes all instanciated forms.

查看:110
本文介绍了单击X按钮将关闭所有实例化的表单.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在按钮上单击创建了一个应用程序,我创建了一个要打开的相同表单的实例,但是当我单击该表单的X按钮时,它将关闭两个表单.我希望当我单击X按钮时,它应该仅关闭特定形式,而不是整个应用程序.

I have made an application on a button click i have created an instance of same form to open but when i click X button of the form it closes both forms. I want that when i click X button it should close only that particular form not the whole application.

推荐答案

那有点复杂:它取决于哪种形式用户关闭.如果是第一种形式,那么确实会关闭整个应用程序-Main方法是通过Application.Run构造它的,当表单关闭时,应用程序也会关闭它.如果用户关闭第二个窗体,则该应用程序不受影响.
解决此问题的最佳方法可能是让应用程序在"program.cs"中打开一个不可见的窗体,并同时打开其他窗体.如果它监视两个表单的表单关闭事件,则可以终止自身并结束应用程序.
That''s slightly complex: it depends on which form the user closes. If it is the first form, then that will indeed close the whole app - the Main method constructs it via Application.Run, and when the form closes, so does the application. If the user closes the second form, the application is not affected.
Probably, your best way to handle this is to have an invisible form which is opened by the application, in "program.cs" and which opens both the others. If it monitors the form closed event for both forms, it can then terminate itself and end teh application.


这篇关于单击X按钮将关闭所有实例化的表单.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆