I have 2 forms. In form1 i have a textbox called TextBox1
In Form2 i have another textbox called TextBox2.
I want the text from textbox1 to textbox2, i tried this.
TextBox2.Text = Form1.TextBox1.Text
Do i need to make changes to the first textbox?
As Joel mentioned you will need to make the
TextBoxcontrol public, be default they areFriendwhich allows other classes/controls/forms in the same Assembly (VB.NET Project) to access the control but not classes/controls/forms from outside the Assembly.The change can be made in two ways, in the GUI Designer or the generated code.
To make the change in the designer:
To change the generated code you will need to:
Locate the TextBox’s declaration, which will be like:
Friend WithEvents TextBox1 As Windows.Forms.TextBox
Change “Friend” to “Public”
On a side-note This works fine, but is generally not a good practice to have controls “reaching into” other controls to get/set values. I understand you’re new to .net so I’ll spare the details, but once you feel you’ve tackled the initial learning curve you’ll want to read into the ideas behind the MVC / MVP / MVVM / MV* patterns–they focus on seperation of logic and UI