3 forms and 3 buttons - to go to each form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buddyr
    New Member
    • Apr 2007
    • 105

    3 forms and 3 buttons - to go to each form

    Hello,
    I have created a windows application w/3 forms and one button on each form.
    I first want to be able to say click button on form1 and get to form2 and have form1 hide.
    I thought this code would work
    Form2 newWindow = new Form2();
    newWindow.Show( );
    this.hide();
    And actually it does work to get me to form 2- but then I thought I could modify code to go from form2 to form3 and then form3 to form1.
    But it doesn't-
    can you help
    thank you
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    The primary problem with your logic is that not every form knows of every other form.

    1 makes a new 2
    2 makes a new 3
    3 has no knowledge of the original 1, so how can it reference it?

    I'll give you a fast "cheat" way so you can keep working/learning.

    In your Program.cs file...
    Code:
    public static Form1 Tommy = new Form1();
    public static Form2 Billy = new Form2();
    public static Form3 Mary = new Form3();
    Now all of your forms have a common point of creation, and the Program.CS file ties them all together with a common point of reference.

    Your instance of form2 (Named Billy) can always call your instance of form3 Program.Mary.Hi de(); for example.

    Comment

    • buddyr
      New Member
      • Apr 2007
      • 105

      #3
      thanks for help and code -

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Better stop hacking at your keyboard and cheating your way into programming. You will only program yourself into a corner that way. Read reply #7 in this thread.

        Comment

        • buddyr
          New Member
          • Apr 2007
          • 105

          #5
          thank you for knowledge- I was a professional musician for years- and I realized some of the things I learned wrong young- later were problems when I was trying to play on a professonal level.

          Comment

          Working...