469,955 Members | 2,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

Passing Data Between Forms

What's the best wat to pass data between two separate forms. For instance,
Form1 invokes Form2 like this:

Form z = new Form2();
z.Show();

How can I pass back strings and boolean values from Form2 to Form1?

Thanks,

Michael C.
Nov 16 '05 #1
2 3489
Micheal,

there are many ways to do this. One of those is

//define form1.
Form pForm1 = new Form();

//during launch of Form 2 do this
Form pForm2 = new Form( pForm1); //pass in constructor.
pForm2.ShowDialog(); or pForm.Show();

//Once when Form2 is displayed, to pass value back to form Set through
properties

example .
mForm1.Mybool = Form2.TestBool;

mForm1 is a member in Form2 which is received in constructor. You can
access public variables and internal variables of Form1 in Form2. The other
ways do is by defining event handlers and delegates.

Shak
"Michael C" <mi*******@optonline.net> wrote in message
news:U4*********************@news4.srv.hcvlny.cv.n et...
What's the best wat to pass data between two separate forms. For instance, Form1 invokes Form2 like this:

Form z = new Form2();
z.Show();

How can I pass back strings and boolean values from Form2 to Form1?

Thanks,

Michael C.

Nov 16 '05 #2
Cool, I was trying to decide if passing the form to the constructor like you
did would be better than using public static variables, etc. I'll use your
method. Thanks!

Michael C.

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:uR****************@TK2MSFTNGP09.phx.gbl...
Micheal,

there are many ways to do this. One of those is

//define form1.
Form pForm1 = new Form();

//during launch of Form 2 do this
Form pForm2 = new Form( pForm1); //pass in constructor.
pForm2.ShowDialog(); or pForm.Show();

//Once when Form2 is displayed, to pass value back to form Set through
properties

example .
mForm1.Mybool = Form2.TestBool;

mForm1 is a member in Form2 which is received in constructor. You can
access public variables and internal variables of Form1 in Form2. The other ways do is by defining event handlers and delegates.

Shak
"Michael C" <mi*******@optonline.net> wrote in message
news:U4*********************@news4.srv.hcvlny.cv.n et...
What's the best wat to pass data between two separate forms. For

instance,
Form1 invokes Form2 like this:

Form z = new Form2();
z.Show();

How can I pass back strings and boolean values from Form2 to Form1?

Thanks,

Michael C.


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Richard | last post: by
6 posts views Thread by Scott Zabolotzky | last post: by
5 posts views Thread by Rod | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.