getting a string from a child form to a parent form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • it0ny
    New Member
    • Feb 2009
    • 4

    getting a string from a child form to a parent form

    Hi guys,

    I am fairly new to visualbasic. A little background from me, I've programmed before in C++, Java, and PHP so I know programming. But I am new when it comes to GUI development too.

    My question is that I have a main form and I've created another small form.
    In the main form I show the small form when they click a button, like this:

    Code:
    Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
      Handles AddButton.Click
            Dim License As LicenseNewForm = New LicenseNewForm
            License.ShowDialog()
    End Sub
    then the LicenseNewForm appears. The problem the I stumble upon is how I get the information from the license form to the main form when they click a button in the license form or close the license form.

    The information is more then just a simple input, so I can't use a InputBox call
    because the license form has 3 comboboxes and a textbox to get the input from the user and then I need to send that input to the main form.

    I don't even know if it is possible, so I thought of asking about it here.

    Thanks for the help in advance.
    Last edited by Frinavale; Mar 2 '09, 02:40 PM. Reason: Moved to VB.NET Answers from .NET
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    question moved to .net forum

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Don't think of it as 'sending' the info to the main form.
      When the child form closes, don't dispose of it.
      It will still exist in memory until it goes out of scope.
      So you display it using the ShowDialog() method. This causes execution to remain on the child dialog until you click the 'ok' button (or whatever button has the DialogResult property of 'accept', to be more accurate).

      From there your main form can just ask the child form what are the values of its controls or variable or properties.

      I went from C++ to C#, so I can't really give you VB code to accomplish it. I know there is a couple other questions very similar to this one in the last couple weeks under the C# forum that have some code samples if you want to browse back a week or two for questions with nearly the same title as this one.

      Comment

      • it0ny
        New Member
        • Feb 2009
        • 4

        #4
        @debasisdas
        thanks, newbie mistake :P

        @tlhintoq
        thanks for the reply. So I can use the form object as an open thread and get the info. That gave me an idea. Thanks.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          A 'thread' is a totally different thing. Start now with keeping terms and mental images straight. It will keep you from having to 'unlearn' bad habits later.

          The child form is an object that you can reference until it goes out of scope.

          If you created the child form from inside a method, then its scope is the lifespan of the creating method. If you create the child form as a 'global' or member object at the creation of your application, then it's lifespan is that of the application. I do some simple tool and control palettes this way.

          Comment

          • OuTCasT
            Contributor
            • Jan 2008
            • 374

            #6
            Originally posted by it0ny
            Hi guys,

            I am fairly new to visualbasic. A little background from me, I've programmed before in C++, Java, and PHP so I know programming. But I am new when it comes to GUI development too.

            My question is that I have a main form and I've created another small form.
            In the main form I show the small form when they click a button, like this:

            Code:
            Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
              Handles AddButton.Click
                    Dim License As LicenseNewForm = New LicenseNewForm
                    License.ShowDialog()
            End Sub
            then the LicenseNewForm appears. The problem the I stumble upon is how I get the information from the license form to the main form when they click a button in the license form or close the license form.

            The information is more then just a simple input, so I can't use a InputBox call
            because the license form has 3 comboboxes and a textbox to get the input from the user and then I need to send that input to the main form.

            I don't even know if it is possible, so I thought of asking about it here.

            Thanks for the help in advance.
            You can add a module to your project and use public strings to hold information until the application is closed or values are reset.
            Or when working with child forms you can call the information using the mdiParents name and then the control on the form.

            Comment

            • kunal pawar
              Contributor
              • Oct 2007
              • 297

              #7
              I guess you want to send information from Child Form to Main form.

              Then create publue properties for Main form.

              and set values from Child form.

              I think this will helps you

              Comment

              • it0ny
                New Member
                • Feb 2009
                • 4

                #8
                thanks OuTCasT and kunal pawar.

                I tried to do it by changing the public variables in the main form, but it didn't work. I couldn't find why.
                So I am using a module now. Thanks for the quick reply guys. you saved my butt.

                Comment

                Working...