Appropriate method for retrieving data from a form

New to C # and .NET.

In a windows app, I put a form to ask the user for some input. The user fills out the form and clicks "ok".

What is the "correct" or "appropriate" method to retrieve this data from a form? Do forms have a return statement? Send a message?

Thanks in advance.

0


source to share


3 answers


This question has been asked in a slightly different form on SO; see my answer here .



+2


source


you can have a parent form to subscribe to events from the child form and still do the same, or put the results of the form in the arg statement of events



you have to listen for the button click event and you will get a callback and you can just read the properties from the form objects (txtBox.Text etc.).

+1


source


After they click OK, the form will close, but (as long as the form variable is still in scope) its members will still contain all the data. Store the input in a member variable and access it from your main program using an accessor. If the form is not modal, your main program can subscribe to the form's close event and then retrieve the information.

0


source







All Articles