如何防止表单对象在关闭时被丢弃?
我正在使用 MDIParent 表单。当我关闭它的孩子时,孩子的对象就会被释放。有没有办法将子级可见性设置为 false 而不是处置?
I am using an MDIParent Form. When I close its child, the object of the child disposes. Is there a way to set child visibility to false instead of disposing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
默认情况下,当您关闭表单时,它将被处理。您必须重写
Closing
事件来阻止它,例如:记住添加方法,例如在表单 ctor 中:
By default, when you close a form, it will be disposed. You have to override the
Closing
event to prevent it, for example:Remember to add the method, e.g. in the form ctor:
您可以取消关闭事件并隐藏。
You can cancel the close event and hide instead.
是的。您可以调用表单的“隐藏”方法。
您还可以重写 OnClosed 并且不调用其基本实现;但是,当您确实想要处理该表格时,这可能会妨碍您。
Yes. You can call the form's "Hide" method.
You can also override OnClosed and not call its base implementation; HOWEVER, when you DO want to dispose of the form, this may get in your way.
当然,您可以取消关闭并隐藏它。这看起来不是一件好事,但你绝对可以。
请参阅Form.FormClosing 事件(MSDN)。
Sure, you can cancel the close and hide it. It doesn't seem like a good thing to do, but you definitely can.
See Form.FormClosing Event (MSDN).