How to "prompt" a subform for user input in VB?

user1452954 picture user1452954 · Jun 21, 2013 · Viewed 11.4k times · Source

Here is what i want to achieve in my project :

When a user press a button, a form pop out with textbox, radio button and select menu on it, allowing the user to input their inform,

Click OK, the form data will be passed to some textbox in the main program form click cancel, the subform just go away

Is this possible in VB ?

I tried prompt and inputbox, but there are limited

I'm new to VB, so sorry if I didn't make the question clear

Answer

tinstaafl picture tinstaafl · Jun 21, 2013

A simpler way is declare a variable of the form you'll use then call the showdialog. Now you can access all the control properties that are on the form. Because you're using an object of form2 closing the form doesn't dispose of the object so everything is available.

    Dim NewForm2 As New Form2
    Dim Result As DialogResult = NewForm2.ShowDialog
    If Result = Windows.Forms.DialogResult.OK Then
        MsgBox(Newform2.TextBox1.Text)
    End If

In Form2 add this:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Me.DialogResult = Windows.Forms.DialogResult.OK
    Me.Close()
End Sub