Form2 send to Form1

G

GoGs

HEEEELLLLLPP

I hawe two Open form... Form1 and Form2

How I can from Form2 send text to textbox of Form1

//public System.Windows.Forms.TextBox textBox1;
//Form1 fo = new Form1();
//fo.textbox1.Text = "something";
--> Don't work
 
M

Michael Nemtsev

Hello gogs,

Try to use google before asking :)
http://groups.google.com/groups/search?q=asp.net+send+data+between+pages

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

g> HEEEELLLLLPP
g>
g> I hawe two Open form... Form1 and Form2
g>
g> How I can from Form2 send text to textbox of Form1
g>
g> //public System.Windows.Forms.TextBox textBox1;
g> //Form1 fo = new Form1();
g> //fo.textbox1.Text = "something";
g> --> Don't work
 
L

Lebesgue

Hello Michael,

While I agree with you he could have googled first, I'm afraid you misread
gogs' question, he was asking about windows forms, not ASP.NET.

Answer to gogs' question:
Keep in mind that forms are still objects. You can have multiple instances
of a particular form class and changing properties of one won't affect other
instances.
You will need to pass a reference to an instance of Form1 to Form2 (either
in constructor or by using a property), make sure the TextBox you need to
change is visible (public or internal) and change it's Text property as you
wanted to do in the example you've posted.

class Form2 : System.Windows.Forms.Form
{
private Form1 form1;
public Form2(Form1 form1)
{
this.form1 = form1;
//InitializeComponents(); or whatever you have in your constructor
}

void DoSomethingToForm1()
{
this.form1.textBox1.Text = "Foo";
}
}
 
P

Peter Bradley

Heh! Gormod o gogs.

If GoGs is Welsh, he'll understand. If not, well, sorry for this misuse of
bandwidth. Blame coincidence.


Peter

Lebesgue said:
Hello Michael,

While I agree with you he could have googled first, I'm afraid you misread
gogs' question, he was asking about windows forms, not ASP.NET.

Answer to gogs' question:
Keep in mind that forms are still objects. You can have multiple instances
of a particular form class and changing properties of one won't affect
other instances.
You will need to pass a reference to an instance of Form1 to Form2 (either
in constructor or by using a property), make sure the TextBox you need to
change is visible (public or internal) and change it's Text property as
you wanted to do in the example you've posted.

class Form2 : System.Windows.Forms.Form
{
private Form1 form1;
public Form2(Form1 form1)
{
this.form1 = form1;
//InitializeComponents(); or whatever you have in your constructor
}

void DoSomethingToForm1()
{
this.form1.textBox1.Text = "Foo";
}
}

Michael Nemtsev said:
Hello gogs,

Try to use google before asking :)
http://groups.google.com/groups/search?q=asp.net+send+data+between+pages

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and
we miss it, but that it is too low and we reach it" (c) Michelangelo

g> HEEEELLLLLPP
g> g> I hawe two Open form... Form1 and Form2
g> g> How I can from Form2 send text to textbox of Form1
g> g> //public System.Windows.Forms.TextBox textBox1;
g> //Form1 fo = new Form1();
g> //fo.textbox1.Text = "something";
g> --> Don't work
 
B

Bobbo

Peter said:
Heh! Gormod o gogs.

If GoGs is Welsh, he'll understand. If not, well, sorry for this misuse of
bandwidth. Blame coincidence.

Peter, I'm a 'gog' so it wasn't wasted!

I think that's enough OT for this thread...
 
G

GoGs

Hello Michael,

While I agree with you he could have googled first, I'm afraid you
misread
gogs' question, he was asking about windows forms, not ASP.NET.

Answer to gogs' question:
Keep in mind that forms are still objects. You can have multiple
instances
of a particular form class and changing properties of one won't affect
other
instances.
You will need to pass a reference to an instance of Form1 to Form2
(either
in constructor or by using a property), make sure the TextBox you needto
change is visible (public or internal) and change it's Text property as
you
wanted to do in the example you've posted.

class Form2 : System.Windows.Forms.Form
{
private Form1 form1;
public Form2(Form1 form1)
{
this.form1 = form1;
//InitializeComponents(); or whatever you have in your
constructor
}

void DoSomethingToForm1()
{
this.form1.textBox1.Text = "Foo";
}
}

YES... Tnx Veeerrrrryyyy, Thanks
Michael Nemtsev said:
Hello gogs,

Try to use google before asking :)
http://groups.google.com/groups/search?q=asp.net+send+data+between+pages

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and
we
miss it, but that it is too low and we reach it" (c) Michelangelo

g> HEEEELLLLLPP
g> g> I hawe two Open form... Form1 and Form2
g> g> How I can from Form2 send text to textbox of Form1
g> g> //public System.Windows.Forms.TextBox textBox1;
g> //Form1 fo = new Form1();
g> //fo.textbox1.Text = "something";
g> --> Don't work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top