Working with multiple forms in vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vksundari
    New Member
    • Jun 2007
    • 5

    Working with multiple forms in vb.net

    Hi All,

    Can u please help in resolving this. I have 2 froms in VB.net namely form1 and from2. i am opening form2 as modal window of form1. After clicking a button on form2, i should set the textbox of form1 with value entered in textbox of form2 by closing the form2.

    Thanks,
    vksundari
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by vksundari
    Hi All,

    Can u please help in resolving this. I have 2 froms in VB.net namely form1 and from2. i am opening form2 as modal window of form1. After clicking a button on form2, i should set the textbox of form1 with value entered in textbox of form2 by closing the form2.

    Thanks,
    vksundari
    Hi Vksundari, Welcome to TDSN!

    Are you creating a web application or desktop application?

    -Frinny

    Comment

    • vksundari
      New Member
      • Jun 2007
      • 5

      #3
      Its a Desktop application. vb.net 1.1

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by vksundari
        Its a Desktop application. vb.net 1.1
        I've only ever created 1 desktop application before so I'll do my best.
        I believe there is a "FormClose" event (or something similar).

        In the vb code for the Form2 select from the drop down menus at the top:
        • your form
        • and the Form Close event.


        This will create the method that handles this event for you.
        In this method you're going to have to refer to Form1.TextBoxTh atMustBeChanged .Text to set its value.

        Hope this helps!

        -Frinny

        Comment

        • TRScheel
          Recognized Expert Contributor
          • Apr 2007
          • 638

          #5
          Originally posted by vksundari
          Hi All,

          Can u please help in resolving this. I have 2 froms in VB.net namely form1 and from2. i am opening form2 as modal window of form1. After clicking a button on form2, i should set the textbox of form1 with value entered in textbox of form2 by closing the form2.

          Thanks,
          vksundari
          First and foremost, I suggest more descriptive names so when you come back to this application in the years to come you have an idea of what you were trying to do.

          If you create an instance of the form, even after it closes its children are accessible. Hence if you add a public property on the form2 that returns the value of what needs to be placed into the textbox, you can take that from the form2 object and place it into the textbox. Following is an example of what I mean:

          [CODE=vb]
          Public Class Form1

          Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
          Dim Form2Instance As Form2 = New Form2()
          MyBase.ShowDial og(Form2Instanc e)
          MyBase.TextBoxI tem.Text = Form2Instance.T heTextBoxsValue ()
          End Sub
          End Class

          Public Class Form2

          Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

          End Sub

          Public Function TheTextBoxsValu e() As String
          Dim result As String = String.Empty
          Return result
          End Function
          End Class[/CODE]

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by TRScheel
            First and foremost, I suggest more descriptive names so when you come back to this application in the years to come you have an idea of what you were trying to do.

            If you create an instance of the form, even after it closes its children are accessible. Hence if you add a public property on the form2 that returns the value of what needs to be placed into the textbox, you can take that from the form2 object and place it into the textbox. Following is an example of what I mean:
            ...
            Thanks TRScheel!

            -Frinny

            Comment

            • vksundari
              New Member
              • Jun 2007
              • 5

              #7
              Thanks TRScheel and Frinny! . I got it.

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Originally posted by vksundari
                Thanks TRScheel and Frinny! . I got it.
                Congrats!

                :)

                -Frinny

                Comment

                Working...