Good morning - I am trying to get a handle on C# but I keep coming up against the most basic of problems that each take me a day or so to overcome.

My present problem is, I'm sure, a very simple one but I cannot find a way to do it in C# - I can in VB.Net using a basic module but I cant find anything similar in C#.Net.

Essentially all I want to do is have two forms, the first will capture some numerical data and have a button to open the second form that captures more numerical data - I then want to return to the first form and use the data from the second form and display a result relating to a calculation involving both lots of data. The data is captured in textboxes by the way. I guess all I want is to have my data "visible" and usable on any form.

To add a level of difficulty, I am programming for a Windows Mobile device but that probably doesn't make much difference.

Can you PLEASE help me ............ I'm beginning to get an aversion to C# as, although there is a lot of material out there to provide examples - there is little that assumes no knowledge at all and those that do - do not address this issue.

With regards


if the numerical data captured is in textboxes in the 2nd form;
select the textboxes in the form and goto properties and change modifiers to public.

in form1 create an object of form2

form2 frm = new form2();

now you can access the textboxes of form2 in form1 by using the object of form2;

ex; here shows assign ment of value of textbox in frm2 to text boxes in form 1

frm2 frm = new frm2();
txtCustID.Text = frm.txtCustID.Text.Trim();
txtName.Text = frm.txtName.Text.Trim();
txtAddress.Text = frm.txtAddress.Text.Trim();
txtCountry.Text = frm.cmbCountry.Text.Trim();
txtDob.Text = frm.dtpDOB.Text.Trim();
txtAge.Text = frm.txtAge.Text.Trim();

hope this helps you

That looks great ITech, thank you - so simple yet so hard to find in the examples. I may be back with other requests down the track so again, thanks for the help.

Well - I thought I understood but I guess my C# knowledge is so poor I dont even know how to find a solution.

Please indulge me one more time and tell me how to do the following:

Your code tells me how to open form 2 but how do I close it before returning to form 1 and still keep the data?

How do I return to form 1 from form 2 without creating a new instance of form 1 ie I have to close at the X form 1 to see the real form 1 if you can understand my logic (the code just creates new forms rather than returning me to the origional form).

This must be a common problem in C# programming but I cant find any examples on how its done so again I request some help.


I might be totally off but have you tried this.close ? or this dot anything (if you have intellisense, just scroll through the menu and see what's in there ;))

Hope this helps!

form2 frm = new form2();

This will never compile!
Should be : Form frm = new Form();
Meaning : make an object frm of type Form. Type form2 may exist, but I don't believe it exists in this context.

This might also help :