Connecting Form1 and Form2

I have made two forms using drag and drop process. Now, I want that if button 1 on form1 is clicked, Form 2 should show up and form1 should hide itself. And if the back button(button1) on form2 is clicked, it should disappear and form1 should be visible again.
Ne help is appreciated


Answer this question

Connecting Form1 and Form2

  • Keith Koh

    Here are some basic tips:

    You want to create an instance of form2 in form1 at Button1_Clicked event.  
    Next open the form2.  Sample code:
    form2 frm = new form2();
    frm.Show();

    I am not sure about hiding form1, you will have to play little with the visible property.

    But if what you want is that the user can not acces form1 before quiting form2, then you want to dispay the form2 as:
    form2 frm = new form2();
    frm.ShowDialog();

    On form2 under Button1_Clicked event:
    this.Close();

    Hopefully this helps.

  • MarketFare

    what if i want to dispose form1, and show the form2, when you click the button1 at form1.

    the prev. one was easy, this is typical.

    brijesh

  • chaospixel

    in form 1 at button1 click

    Dim form2 As New Form2
            form2.Show()
            Me.Hide()

    ------------------------------------
    in form 2 at button1 click

    Dim form1 As New Form1
            form1.Show()
            Me.Hide()

  • Connecting Form1 and Form2