hi i have this problem:
private void Form5_Load(object sender, System.EventArgs e)
{
Form1 frm1 = new Form1();
string name = frm1.textBox1.Text;
MessageBox..Show(name);
}
on the Form5 i wrote that code.....ill explain u what the program do:
u start in Form1 and when u click in a button it ShowDialog the Form5 and in the Form5_Load it should get the text in the textBox1 of Form1 and MessageBox the text it get.
the problem is that i allways get a blank messagebox... and i allready checked that the textBox1 have text in it.. i also made oublic the textBox1 so... what can i do

Controls in diferents forms
dflAdam
Object reference not set to an instance of an object
ShadowedOne
Form5
f = new Form5();f.ShowDialog(
this);Lee Eden
rpp
You can do someting, like this in the load
MessageBox.Show(((Form1)this.Owner).textBox1.Text);
But now, I ask, why you need to do someting like this
ozgecolak
Hi,
You can change the declaration of your textbox from private into public. To do this, click the control in design vew and in the properties window search for the Modifier property and change it to public...
cheers,
Paul June A. Domag
SCulver
Hi,
Sorry, I haven't read all of your post (i really must change this habbit). bistok's post is correct. But just to make it clearer, you should make your Form1 be the Owner of Form5 you can do this by setting the owner property of Form5 to your Form1. Confused well here's a code snippet that does that:
// On your Form1, upon displaying form5
private void button1_Click(object sender, System.EventArgs e) {
Form5 frm5 = new Form5();
frm5.Owner = this;
}
// just like what bistok posted you can access your form like this.
private void Form5_Load(object sender, System.EventArgs e)
{
Form1 frm1 = (Form1) this.Owner;
string name = frm1.textBox1.Text;
MessageBox..Show(name);
}
cheers,
Paul June A. Domag
Rahl
newone
Sven_C
That don't work because this: Form1 frm1 = new Form1(); Creates a new instance of the Form1, and that instance don't have text in TextBox1.
JonathanEdwards
Hi,
No, this would just let you access the control on another form. This routine would give you rights to change the other forms button text to something that you want. It gives you control over the controls on the other form.
BTW, are you an ilocano as in from ilocos, phil
cheers,
Paul June A. Domag