How to pass values back to called form

C

Chane

hi
i have doubt in how to pass values back to the called
form. I have two forms, each having a textbox and a button
control. First i'm run the first form and click the
button, it creates object for second form and showed as
modaless. And i entered some text in second form's
textbox. While i clicked the seconds form's button the
value in textbox of second form to be transfered to first
form textbox. Thanx
 
J

Jon Skeet [C# MVP]

Chane said:
i have doubt in how to pass values back to the called
form. I have two forms, each having a textbox and a button
control. First i'm run the first form and click the
button, it creates object for second form and showed as
modaless. And i entered some text in second form's
textbox. While i clicked the seconds form's button the
value in textbox of second form to be transfered to first
form textbox. Thanx

When you create the second form, make sure it knows about the first
form (pass it as a reference in the constructor, for instance) and give
some way in the first form of receiving the new value. Just think of
the forms as ordinary objects, and how you'd do this if the GUI wasn't
involved at all.
 
W

Wajih-ur-Rehman

There can be two ways

1. Pass the reference of form1 to the form2. Using that reference from
form2, access the text box (it should be public or if you want to keep it as
private then you would have to create a public property to access it) of
form1 and set the text there.

2. Create a pubilc property in form2 which will be set with the text when
you press that button. Since form1 has the reference to form2, use that
reference and access the public property of form2 and then set it in the
text field of form1.

I hope it helps..
 

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