[已解决]隐藏子窗体而不是关闭它 [英] [Solved] Hiding a child form instead of closing it

查看:132
本文介绍了[已解决]隐藏子窗体而不是关闭它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使表单保持活动状态,但隐藏而不是关闭它.我认为也许我需要截取关闭消息并进行更改,然后改为调用Hide().主(父)表单应在退出时配置子表单.我想我了解这些原则,但我不知道如何将其付诸实践

现在,我已经在主窗体标题中声明了子窗口,对其进行了初始化,并在单击相应按钮时将Show()设置为适当的窗体.但是,当我关闭它时,Windows会自动处理它,并尝试取消隐藏它显然不起作用.

任何帮助都值得赞赏,但迫切需要.

如果intellisense可以工作,这会容易得多...

Hi, I''m trying to keep a form active but hidden rather than closing it. I think maybe I need to intercept the close message and change it, then call Hide() instead. The main (parent) form should dispose the child forms on exit. I think I understand the principles, but I don''t know how to put it into practice

At the moment I have declared the child windows in the main form header, initialised them and Show() the appropriate form when the corresponding button is clicked. However when I close it, windows automatically disposes it and trying to un-hide it obviously doesn''t work.

Any help much appreciated, but needed quite urgently.

This would be much easier if intellisense were working...

推荐答案

此处是操作方法:覆盖System::Windows::Forms::Form.OnFormClosing方法:

Here is how to do it: override System::Windows::Forms::Form.OnFormClosing method:

virtual void OnFormClosing(System::Object ^sender, System::Windows::Forms::FormClosingEventArgs ^e) {
   if (e->CloseReason == System::Windows::Forms::CloseReason::UserClosing) {
      Hide();
      e->Cancel = true;
    } //if
} //OnFormClosing



您不必担心Dispose,它将被称为,因为表格保存在Application下.


覆盖此方法肯定比处理事件FormClosing更好.在上面显示的小码中,Hide实际上是"this->Hide()",因此该实例已经传递给该方法.对于事件,发件人需要类型转换为Form.

—SA



You don''t need to worry about Dispose, it will be called as the form is kept under the Application.


Overriding this method is certainly better than handling the event FormClosing. In the codelet shown above, Hide is actually "this->Hide()", so the instance is already passed to the method. With event, sender needs to be typecast to Form.

—SA


这篇关于[已解决]隐藏子窗体而不是关闭它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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