Question Replicating data in textbox from one form to another.

gho5t

Member
Joined
Aug 26, 2013
Messages
13
Programming Experience
1-3
Been trying and trying and can't seem to get it to work.

This is what i'm trying to accomplish.

Form1 has textbox1
Form2 has textbox2

textbox2 = textbox1

How would i do so?

Please help with working method.
 
Hi and welcome to the Forum,

Assuming that what you mean is to show the Text in TextBox1 on Form1 in TextBox2 on Form2 then you can use a Constructor in Form2 to pass the Text value from TextBox1 to Form2 and then the Constructor sets the Text value in TextBox2. i.e:-

Define the Constructor you need in Form2:-
VB.NET:
Public Class Form2
  Public Sub New()
    ' This call is required by the designer.
    InitializeComponent()
    ' Add any initialization after the InitializeComponent() call.
  End Sub
 
  Public Sub New(ByVal strSomeTextFromForm1 As String)
    ' This call is required by the designer.
    InitializeComponent()
 
    ' Add any initialization after the InitializeComponent() call.
    TextBox2.Text = strSomeTextFromForm1
  End Sub
End Class

Then open Form2 with the following code:-
VB.NET:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  Dim myForm2 As New Form2(TextBox1.Text)
  myForm2.Show()
End Sub

Hope that helps,

Cheers,

Ian
 
Back
Top