Returning values FROM window form
(Thursday, December 23, 2004)
Found the following interesting discussion in the Newsgroups:
returning values FROM window form by:Graham Blandford
| Hi all,
Quickie - I hope. I already know how to use a forms New() Sub to receive parameters from a calling class - but I don;t know how to return values...
Anyone know the recommended method for doing this?
Thanks, Graham
| | | Reply: by:William Ryan eMVP
| | | Create some properties corresponding to each of those values, or create a class that holds all of them and make a property of that class in your target form.
Before that form closes, set them all...
this.FirstValueYouWantReturned = Whatever; or me.FirstValueYouWantReturned = Whatever (vb.net) and repeat this for each varaible. Assume these properties were added to Form2.
So...
Form2 frm = new Form2(SomeValue, SomeOtherValue);//this means you passed in two variables frm.Show();
or Dim frm as Form2 = new Form2(SomeValue, SomeOtherValue) frm.Show()
now, in form2 set those properties as I showed you above to the values you want returned
string FirstValue = frm.FirstValueYouWantReturned; string SecondValue = frm.SecondValueYouWantReturned;
same process for VB.NET at this point.
Or you coudl just create one property of type someClass that contains all of the variables. Then you set them in the class (remember, it's still a property of Form2 which is essential to either approach, this just consolidates it).
then
string FirstValue = frm.SomeObject.FirstValueYouSet; string SecondValue = frm.SomeObject.SecondValueYouSet;
HTH,
Bill
-- W.G. Ryan MVP Windows - Embedded
http://forums.devbuzz.com http://www.knowdotnet.com/dataaccess.html http://www.msmvps.com/williamryan/
| | | Reply: by:Graham Blandford
| | | Thanks Bill.
I'll give it a try.
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | Add properties to the form and set the property values inside the form.
-- Herfried K. Wagner [MVP]
|
|
|
|
|
0 Comments:
Post a Comment