locked
How Do I make a link? RRS feed

  • Question

  • I am trying to make a button on form1 to link to form2, and I do not know how to do that, please reply if you know.
    Monday, September 19, 2005 10:22 PM

Answers

  • As you've asked on a VB forum, I need to make some assumptions.

    1.  I assume you're not using ASP.NET
    2.  I assume you ARE using VB.NET.

    A form is just a class - the forms designer gives you a graphical view, but everything you do there goes into the InitializeComponent method, where all those GUI controls are created and their properties set.  As such, you create a form like you create any other class instance.  Then, once you have it, you can call a method on the instance called ShowDialog method will show the new form, and the old form will not respond until the new one closes.  This is called a modal dialog.  There's also a show method, this will show the form, but leave your other form responsive as well.  To use this, make your instance of Form2 a member variable, so you can access it from the entire class.

    ShowDialog returns a variable of type DialogResult.  You use this return value to find out what button the user pressed to close the form ( for example, OK or Cancel ).  You can set which button does what by setting the dialog result property on buttons, and the acceptbutton and cancelbutton properties on the form ( the latter sets the property if a user closes the form without pressing one of your buttons ).
    Monday, September 19, 2005 10:28 PM
    Moderator

All replies

  • As you've asked on a VB forum, I need to make some assumptions.

    1.  I assume you're not using ASP.NET
    2.  I assume you ARE using VB.NET.

    A form is just a class - the forms designer gives you a graphical view, but everything you do there goes into the InitializeComponent method, where all those GUI controls are created and their properties set.  As such, you create a form like you create any other class instance.  Then, once you have it, you can call a method on the instance called ShowDialog method will show the new form, and the old form will not respond until the new one closes.  This is called a modal dialog.  There's also a show method, this will show the form, but leave your other form responsive as well.  To use this, make your instance of Form2 a member variable, so you can access it from the entire class.

    ShowDialog returns a variable of type DialogResult.  You use this return value to find out what button the user pressed to close the form ( for example, OK or Cancel ).  You can set which button does what by setting the dialog result property on buttons, and the acceptbutton and cancelbutton properties on the form ( the latter sets the property if a user closes the form without pressing one of your buttons ).
    Monday, September 19, 2005 10:28 PM
    Moderator
  • I am trying to do exactly the same thing. Are you and I the only ones who have had that "original" thought? Click a button and go to the next form? If I wanted to link to hypertext I would have put it in the search area. I didn't want anything in C# I wanted it in Visual Basic (2005). I'd rather not have any answer than to have 100 "answers" that didn't answer a straightforward question. It would seem to have been a "boolean" response. I understood your question exactly. Dan the frustrated.
    Saturday, April 7, 2007 11:19 AM
  • Hi Dan,

    A Button1 (on Form1) could have the following code in its Click eventsub, to create a new Form2 and show it to the user:


        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim zNewForm As New Form2

            zNewForm.Show()
        End Sub
    Sunday, April 8, 2007 4:43 AM
  • Really, really, really, I do appreciate your response.

    I hope I made it clear that I was frustrated. I apologize.

    Your response is helpful as it at least points me in a direction.

    Thank you

    gascitydan@yahoo.com

     

    Friday, June 1, 2007 3:08 PM
  •  nogChoco wrote:
    Hi Dan,

    A Button1 (on Form1) could have the following code in its Click eventsub, to create a new Form2 and show it to the user:


        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim zNewForm As New Form2

            zNewForm.Show()
        End Sub

     

    Hi,

     

    That would create a NEW copy of Form2 as a Form is a CLASS.

     

    Why not just use

     

     Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

     

    Form2.Show()

     

    End Sub

     

     

    You can in the latest "Orcas" edition, i am not sure about other versions, but either way if you leave NEW out then you are referring to the 1st instance of FORM2.

     

     

     

    Regards,

     

     

    S_DS

     

    Friday, June 1, 2007 8:21 PM