打开第二个formin C# [英] Open second formin c#

查看:134
本文介绍了打开第二个formin C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从C#中的第一个表单中打开第二个表单?

how to open second form from first form in c# ?

推荐答案

其中有一个小技巧,因此许多初学者在阅读常规MSDN帮助时会感到困惑.页面:
http://msdn.microsoft.com/en-us/library/system. windows.forms.form.aspx [ ^ ].

原因是:即使可以关闭表单,也没有打开表单"这样的概念.您只需使用其构造函数创建一个表单,然后调用方法ShowShowDialog来显示模拟的模态对话框行为.但是,我强烈建议使用关系所有权表单/所有者表单,因此最好保留主表单和所有其他非模式表单的所有者,请使用AddOwnedForm,请参见:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform.aspx [ ^ ].

就这样.

是的,最好不要使用MDI,不要用这种丑陋的设计风格来折磨自己并吓跑用户.如果您有任何疑问,我会解释.

—SA
There is a little trick in it, so many beginners get confused when reading a usual MSDN help page:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[^].

The reason is: there is no such concept as "open a form", even though a form can be closed. You simply create a form with its constructor and later call the method Show or ShowDialog to show imitating modal dialog behavior. However, I strongly recommend to use the relationship owned form / owner form, so better keep the main form and owner of all other non-modal forms, use AddOwnedForm, please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform.aspx[^].

That''s it.

And yes, better never use MDI, don''t torture yourself and scare off your users with this ugly design style. If you have questions on it, I''ll explain.

—SA




在Visual Studio中创建一个表单,然后指定要打开的表单的名称,即"openedform"

单击按钮或使用以下代码即可:
Hi,

Create a form in your Visual Studio and then specify name of your to be open form, i.e ''openedform''

Use code below at button click or whatever:
openedform frm = new openedform();
frm.Show(); // or frm.ShowDialog() to open a form as dialog



希望有帮助.



Hope this help.


您好,
当您创建应用程序时,它会提供1个来自.只需右键单击该项目并添加新表单.
然后在Form1类中为Form2创建一个对象.
Form2 objForm2 =新的Form2();
objform2.Show();


此外,如果要在Form1的Form2中进行任何更改,最好将这种形式的当前对象发送到Form2,方法是

Form2 objForm2 =新的Form2(this);
objform2.Show();

为Form2创建一个副本构造函数.
Hi,
when you create application it is provided with 1 from. Just Right click on the project and add new form.
then create a object for the Form2 in Form1 Class.
Form2 objForm2 = new Form2();
objform2.Show();


Further, if you want to change any thing in Form1 form Form2, better to send the current object of form1 to Form2, this way

Form2 objForm2 = new Form2(this);
objform2.Show();

create a copy constructor for the Form2.


这篇关于打开第二个formin C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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