Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
Sergey Alexandrovich Kryukov 30-Oct-12 21:18pm    
Not only this code won't work, it won't even compile. Ever heard that C# is a case-sensitive language? :-)
--SA
Sergey Alexandrovich Kryukov 30-Oct-12 21:29pm    
OP commented:

ok i never knew that
i guess i will try some other codes
Sergey Alexandrovich Kryukov 30-Oct-12 21:32pm    
No, don't try code, write it with full understanding of every single line. Try-and-error approach will get you nowhere. Better step back and do simpler things with good understanding.

Also, you should not post comments like that as "solution". "Add your solution here" anchor is for answers and solutions, for providing some kind of help. Such non-solution posts will be removed; and no one will get notifications. You need to comment on existing posts ("Reply" to comment on comments). Also, use "Improve question".

--SA

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900