pass a variable from one form to another

  • Thread starter Thread starter Mikey
  • Start date Start date
M

Mikey

I'm really new at the c# scene and I think I've proabably
jumped in the deep end :)

I'm really interested in developing Windows Applications
but most sources seem to deal with web development and c#.

So can anyone help me with the following:

This one relates to a project I've started. How can I
make the contents of textboxes in form1 available to form2
in a Windows Application?

Can anyone give me the address of some good sites dealing
with c# and Windows Apps

thanks in advance.........
 
Mikey,

You probably want to start off with http://www.windowsforms.com. This
is a good start. You might also want to check out http://www.gotdotnet.com.

To do what you want to do, you will first have to set the accessor for
all of the controls in your project (or at least the ones that you want to
access) to public. Once you have that, then you can pass the instance of
your form with the controls you want to access to the second form, either
through a property, or through a parameter on a method. A form is like any
other object that you pass around and set values on.

Hope this helps.
 
Nicholas,

Thanks for the sites - I've been browsing them most of the
day and picked up bits and pieces - thanks again.

I must say I'm a bit dumb though - no matter what I tinker
with I can't get form2 to 'see' any of the data from form1.

For example, I have a text box named txtDrv and I want to
be able to pass txtDrv.Text as a string in form1 and
form2 - form1 is fine, but as I say, I can't get form2 to
see it.

I'm sure it's not that hard but I'm being dumber than
usual I think :) so any help would be great, even if
someone can spare the time to give me an example of what
to type and where to put it in the code.

Sorry for the hassle....
-----Original Message-----
Mikey,

You probably want to start off with
http://www.windowsforms.com. This
is a good start. You might also want to check out http://www.gotdotnet.com.

To do what you want to do, you will first have to set the accessor for
all of the controls in your project (or at least the ones that you want to
access) to public. Once you have that, then you can pass the instance of
your form with the controls you want to access to the second form, either
through a property, or through a parameter on a method. A form is like any
other object that you pass around and set values on.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I'm really new at the c# scene and I think I've proabably
jumped in the deep end :)

I'm really interested in developing Windows Applications
but most sources seem to deal with web development and c#.

So can anyone help me with the following:

This one relates to a project I've started. How can I
make the contents of textboxes in form1 available to form2
in a Windows Application?

Can anyone give me the address of some good sites dealing
with c# and Windows Apps

thanks in advance.........


.
 
http://www.syncfusion.com/FAQ/WinForms/FAQ_c95c.asp#q952q

--
William Stacey, MVP

Mikey said:
Nicholas,

Thanks for the sites - I've been browsing them most of the
day and picked up bits and pieces - thanks again.

I must say I'm a bit dumb though - no matter what I tinker
with I can't get form2 to 'see' any of the data from form1.

For example, I have a text box named txtDrv and I want to
be able to pass txtDrv.Text as a string in form1 and
form2 - form1 is fine, but as I say, I can't get form2 to
see it.

I'm sure it's not that hard but I'm being dumber than
usual I think :) so any help would be great, even if
someone can spare the time to give me an example of what
to type and where to put it in the code.

Sorry for the hassle....
-----Original Message-----
Mikey,

You probably want to start off with
http://www.windowsforms.com. This
is a good start. You might also want to check out http://www.gotdotnet.com.

To do what you want to do, you will first have to set the accessor for
all of the controls in your project (or at least the ones that you want to
access) to public. Once you have that, then you can pass the instance of
your form with the controls you want to access to the second form, either
through a property, or through a parameter on a method. A form is like any
other object that you pass around and set values on.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I'm really new at the c# scene and I think I've proabably
jumped in the deep end :)

I'm really interested in developing Windows Applications
but most sources seem to deal with web development and c#.

So can anyone help me with the following:

This one relates to a project I've started. How can I
make the contents of textboxes in form1 available to form2
in a Windows Application?

Can anyone give me the address of some good sites dealing
with c# and Windows Apps

thanks in advance.........


.
 
Back
Top