tags:

views:

263

answers:

4

Hello,

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?

+1  A: 

You will need to reference the instance of the form. Form1 is the class.

Erik
VB uses something called default form instance - often the "class" also _is_ the instance.
Joel Coehoorn
+2  A: 

Controls in windows forms are not public by default. You either need to change the declaration of the TextBox on form1 to explicitly make it public or add a public property to form1 that gets and sets the textbox text (preferred) .

Joel Coehoorn
How can i do this? I'm very new to vb.net
PandaNL
+1  A: 
STW
Made the changes, its on public but i get an error saying System.ArgumentNullException: Argument cannot be Nothing.Parameter name: fileTextBox2 on form1 has text in it so i dont get it.
PandaNL
that argument indicates the error is on a method call that requires a parameter, which doesn't sound like it's related to reading the text value. In Visual Studio, try pressing "Ctrl-Alt-E" and placing a checkmark in the box under "Thrown" next to "Common Language Runtime Exceptions". This will take you to the offending code right when the exception occurs.
STW
Would you my taking a look at the code? I created a new project to test it and everything works perfect, but on this project it doesnt seem to work. If u want to take a look at it contact me on [email protected]
PandaNL
if you have a working and non-working version then you should be able to whittle down the differences and solve it yourself. Make a full copy of your non-working project (or check it into source control) so that you have a point to return to, then consolidate the differences one by one till you find it.
STW
A: 

As I already answered you in this post you have all your code.

You should not access the Form2.TextBox directly, but to pass the textbox text as parameter in constructor OR via a public field (or property) of the second form.

This works, surely, if you can(and have necessary minimum knowledge of VB.NET in order to) modify the Form2 code.

If not, you should declare a unique (Shared in VB.NET) instance of Form2, that is make it Public Shared myUniqueForm2 as Form2 then access the TextBox2 via myUniqueForm2.TextBox2

If the post are still unclear for you, you should stop asking people and read some short basic articles about Object Oriented Programming (OOP) and VB.NET.

By example this one or this one. A lot of tutorials about VB.NET you can find also here.

serhio
The code works fine now, made some stupid mistake. the code was loaded before i had text in my textbox. Fixed it and it works perfect for me.
PandaNL
that was evident, but you should restructurate you code.
serhio