如何在C#中隐藏表单 [英] How to hide forms in C#

查看:151
本文介绍了如何在C#中隐藏表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个具有多种形式的程序.当用户单击主表单上的按钮时,它将带他到另一个表单.但是,它使主窗体作为窗口运行.我希望当用户单击主窗体中的按钮以关闭主窗体并运行其他窗体时.基本上,在过渡到新表单后,如何关闭不希望运行的表单?

Hi, I was making a program which had multiple forms. When the user clicks a button on the main form, it takes him to another form. However, it keeps the main form as a window running. I want when the user clicks on the button in the main form to close the main form and have the other form running. Basically how do i close forms i don''t want running after I have transitioned to a new form?

推荐答案

myForm.Hide [ myForm.Close [
myForm.Hide[^] to set the visibility to False.
An alternative would, of course, be myForm.Visible = False
myForm.Close[^] to close a Form and completely Dispose of it.


AFAIK,您无法关闭所有者(主)表单并保持应用程序运行.您可以使主窗体不可见(不是一个好主意),也可以将新窗体显示为模式对话框.解决方案取决于您的确切要求.

希望对您有帮助!
AFAIK you can''t close the owner (main) form and keep the application running. You can make main form invisible (not a good idea) or show the new form as modal dialog instead. The solution depends on what is your exact requirement.

Hope that helps!


在您的MDI表单中,检查是否存在称为MDIChildren和Active MDIChild的属性(在代码视图中).

以这种方式使用
this.ActivateMdiChild


获取当前的MDI活动子级.

注意:在主窗体的属性中,IsMDI容器应设置为true.
并且从主表单代码打开表单的时间将为.

Form2 f2 = new Form2();
f2.MDIParent = this;
f2.Show();
In your MDI form check that there is property(in code view) called MDIChildren and Active MDIChild.

use in this way
this.ActivateMdiChild


to get the current MDI Active Child(s).

note: In your main form''s property the IsMDI Container should set as true.
and the time of opening the form from Main form code will be.

Form2 f2=new Form2();
f2.MDIParent=this;
f2.Show();


这篇关于如何在C#中隐藏表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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