如何从Form 1访问Form 2 [英] How to access Form2 from Form1

查看:103
本文介绍了如何从Form 1访问Form 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用C#进行winform项目。我创建了form1。我需要创建Form2,当我单击Form1中的按钮时,它应该指向Form2。我该怎么做呢??如果我必须在form2中创建form2的引用,我是否在main()方法中执行此操作?我真的很感激,如果有人可以帮助我,因为我是C#

I am currently doing a project on winform in C#. I have created form1. I need to create Form2 and when I click a button in Form1 it should direct me to Form2. How do I do this?? If I have to create an reference of form2 in form2 , do I do this in the main() method? I really appreciate if someone can help me on this, since I am new to C#

推荐答案

的新手。

引用form2,然后创建一个事件处理程序,创建表单然后显示它,你也可以隐藏form1。
Hi,
Make a reference to form2, then make an event handler, create the form then show it, you can also hide form1.

form2 f2;

f2 = new form2 ();

f2.Show();

this.Hide();
form2 f2;
f2 = new form2 ( ) ;
f2.Show ( ) ;
this.Hide ( );



试试这个并告诉我是否有问题。

问候,

Bassem

Try this and tell me if there is a problem.
Regards,
Bassem


等待被拍下来进行糟糕的编码....


我一直在使用它 -


Form1

waits to be shot down for lousy coding ....

I have been using this -

Form1

展开 | 选择 < span class =codeDivider> | Wrap | 行号


如果您继续创建新表单,您将创建表单的新实例,因此将丢失表单中的数据和字段,并最终使用更多的内存,这就是为什么我在开始时声明了新表单并创建了在form1(mainform)上的引用,以便它可以再次显示
if you keep on creating a new form you will create a new instance of the form so will lose data in and fields on the form and also end up using more memory and that is why I have declared the new form at the start and also created a reference on form1 ( mainform ) so that it could be shown again


这篇关于如何从Form 1访问Form 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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