Passing values from form to form

I have 3 textboxes on Form1 which a user inputs values (x,y,z).

On Form2, I would like to use those values.

I create properties in Form1 as follows:

 public int UserValueX
        {
            get { return x = Int16.Parse(txtX.Text); }
        }

public int UserValueY
        {
            get { return y = Int16.Parse(txtY.Text); }
        }

 public int UserValueZ
        {
            get { return z = Int16.Parse(txtZ.Text); }
        }

Form2 is launched by clicking a button on Form1.

On Form2, I use the following code to retrieve the values (x,y,z) from Form1.

// Get x, y and z values from Form1 User Input

Form1 frm = new Form1();
x = frm.UserValueX;
y = frm.UserValueY;
z = frm.UserValueZ;

I have the default Text properties of x,y,z set to 4 before I start the application.  When I change x,y, or z on Form1, and use the button to launch Form2, I recieves the default Text property values instead of the ones I have changed them to.

Can someone point out to me what I am doing wrong?

LVL 10
rivusglobalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Why not make x, y and z public properties on Form2?  Then you can create your instance of Form2 and set the values before displaying the form:

    // from the Button click event in Form1...
    Form2 frm2 = new Form2();
    frm2.UserValueX = Int16.Parse(this.txtX.Text);
    frm2.UserValueY = Int16.Parse(this.txtY.Text);
    frm2.UserValueZ = Int16.Parse(this.txtZ.Text);
    frm2.Show();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rivusglobalAuthor Commented:
Thanks Idle. That did the trick.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.