locked
Why won't form1.show() work? RRS feed

  • Question

  • This is a simple 2 form application, created by selecting New|C# Project from VS 2010.

    I then added a second form, call it form2.cs.

    I added some controls on Form2.cs.

    I added a button on Form1.cs

    Double click button on Form1.

    Intellisense picks up Form2 as I type - press the period (.) and there's no Show() method.

    Type in show(); anyway and it tells me that form2 does not contain a definition for SHOW()!

    What gives?  Why does it do this to me today, must I just sit here and cry maybe?

    Help...

    Thursday, May 3, 2012 3:14 PM

Answers

  • You need to create an instance of Form2 to show.  For instance:

    Form2 l_form = new Form2();
    l_form.Show();


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    • Proposed as answer by Rudedog2 Thursday, May 3, 2012 5:45 PM
    • Marked as answer by Mike Dos Zhang Monday, May 7, 2012 8:37 AM
    Thursday, May 3, 2012 3:27 PM

All replies

  • You need to create an instance of Form2 to show.  For instance:

    Form2 l_form = new Form2();
    l_form.Show();


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    • Proposed as answer by Rudedog2 Thursday, May 3, 2012 5:45 PM
    • Marked as answer by Mike Dos Zhang Monday, May 7, 2012 8:37 AM
    Thursday, May 3, 2012 3:27 PM
  • Exactly as TSoftware explained. You must use a keyword new, this creates a new instance of Form1 object. And on this instance then you can call Show() method.

    You can even do it in short way:

    new Form2().Show();
    if you do not use the Form`s referecne (like l_form in TSoftware`s example), you can do it like I did.

    Mitja

    Thursday, May 3, 2012 4:42 PM