[VB .NET]Using the content of a textbox in another form

hobbes2103

Active member
Joined
Jul 10, 2003
Messages
43
I have a textbox (textbox1) in my form1
I want to use the content of this textbox in my form2

I have tried to write in form2 :
dim form1 as new form1
str = form1.textbox1.text
but it doesnt work... :(
 
you could do it this way :
In Form1 :
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm2 As New Form2()
        AddOwnedForm(frm2) /// make form2 an owned form of Form1
        frm2.Show()
    End Sub

in Form2 :
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm1 As Form1 = Me.Owner
        frm1.TextBox1.AppendText("some text from Form2 , to Form1!")
    End Sub
 
Back
Top