如何打开从Form1到Form2的表单 [英] how to open a form from form1 to form2

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

问题描述

嘿,刚开始使用c#
我需要帮助才能从表单中打开表单
例如:
当我单击form1上的按钮时,form2将显示
我已经试过了这段代码,但是它一直在给出错误

代码示例:form2.show();

我真的需要帮助.

hey just started using c#
and i need help in order to get a form to open from a form
example:
when i click a button on form1,form2 will show
i have tried this code but it just keep giving error

code example: form2.show();

i really need help

推荐答案

在本论坛中讨论这太微不足道了,所以我将尽快进行.首先,请参阅我对这个问题的评论.另外,您需要解释和理解表格"是什么意思?它可以是派生自System.Windows.Forms.Form的类(包括此类本身),也可以是对象,是该类的实例.要调用Show,您需要一个实例,因为该方法是实例方法(非静态).此外,这是引用类型.称为form2的某种类型的变量或成员是引用,并且不应为null,而应引用某些确实存在的对象.也就是说,该对象可能未通过构造函数的调用进行初始化:new Form().

最后,切勿使用诸如anything1anythingElse2等的名称.这些名称应始终是语义性的.我知道它们来自哪里-来自设计师.切勿使用自动生成的名称,请始终保留它们.这样的名称甚至违反了(好的)Microsoft命名约定.

您的信息不足以准确地找出所有问题,但这足以使您走得更远.但是,下次要确保您提供全面的问题报告吗?如何?对于初学者,想象一下应该回答的人是你.您是否需要更多信息来回答?什么样的信息?当您学习如何回答此类问题时,您将能够生成确实可以从CodeProject获得答案的问题.

祝你好运,
—SA
This is all too trivial to discuss in this forum, so I''ll try to do it quickly. First, please see my comment to the question. Also, you need to explain and understand what do you mean by "form"? It could be a class derived from System.Windows.Forms.Form (including this class itself), or it could be an object, an instance of this class. To call Show, you need an instance, as this method is the instance method (non-static). Besides, this is a reference type. The variable or member of some type called form2 is reference, and it should not be null, but should reference some really existing object. That said, the object might be not initializes with the call of the constructor: new Form().

Finally, never use names such as anything1, anythingElse2, etc. The names should always be semantic. I know where they come from — from the designer. Never use auto-generated names, always remain them. Such names even violate (good) Microsoft naming conventions.

Your information was not enough to figure out all your problems exactly, but this should be enough for you to go further. However, next time make sure you provide comprehensive issue report? How? For starters, imagine that the person who is supposed to answer is you. Will you require more information to answer or not? What kind of information? When you learn how to answer such questions, you will be able to generated questions which really can get answers from CodeProject.

Good luck,
—SA


这篇关于如何打开从Form1到Form2的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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