What's the best way to make a form return a value??

  • Thread starter Thread starter Ale K.
  • Start date Start date
A

Ale K.

What's the best way to make a form return a value.... i want to try to avoid
using module variables for doing this...

Thanks.
Alex.
 
If you want to use a form like a dialog box, then you can use the showDialog
method, on the submit button you can me.hide and then on the following line
to the line calling the show method simply reference the forms members.
 
Alex,
As OHM stated. You can use ShowDialog on your form.

In addition to manually calling me.Hide within the 'Submit' button, you can
have the form take care of it.

To do this you need to:
1. Set the Control.DialogResult value for your Submit/Ok button to
DialogResult.Ok
2. Set the Control.DialogResult value for your Cancel button to
DialogResult.Cancel
3. Set the Form.AcceptButton to your Submit/Ok button
4. Set the Form.CancelButton to your Cancel button

Then the form will take care of everything for you. Which ever button your
press will be the value returned from the ShowDialog call.

Dim dialog As MyDialog1
Select Case dialog.ShowDialog()
Case DialogResult.Ok
' the Submit/Ok button was pressed
Case DialogResult.Cancel
' the Submit/Ok button was pressed
' most of the time you just want to ignore cancel...
End Select
dialog.Dispose()

You can set other buttons to the other values of DialogResult and they will
be returned also. The Form's AcceptButton & CancelButton properties enable
Enter & Esc on the keyboard to be used for those buttons.

Then as OHM & Ed stated, your form class would expose properties to get the
values entered. You can use Properties to set any initial values. Similar to
how OpenFileDialog works.

Remember to call the Dispose method on your form, when you are done so that
it gets cleaned up.

Hope this helps
Jay
 
Remember to call the Dispose method on your form, when you are done so
that
it gets cleaned up.

Hi Jay,

It's interesting you should say that as I have just been wondering as of
late, is it best to dispose of *every* idisposable object?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Nak,
Yes, with exceptions ;-)

My understanding is if you call Form.Show, then Form.Close will call Dispose
for you, however if you call Form.ShowDialog then Form.Close will not call
Dispose for you. As when calling Form.ShowDialog you are normally wanting to
retrieve values from the form after the form is closed. Hence you need to
manually call Dispose...

Also I understand that when the form gets disposed it disposes of all its
children.

Currently that's the only actual exception that I know of.

Jay
 
I think I'm going to Me.Dispose(). Its seems that I can never give enough
of an answer in the eyes of this group. Someone allways has do out do the
other one here.

I'm not taking away anything from the answers given here as they are
excellent if not a little verbose sometimes.

No disrespect to Jay as Jay allways give a very good answer.

But, maybe people like me should stand aside and let only the experts
answer.
 
OHM,
Then I need to:

GC.SupressFinalize(OHM)

Remember the ones that you consider "an expert" are learning also.
Personally one way to become an expert is to hang in there (here) and answer
questions, which is part of the reason I answer questions here. It exposes
me to aspects of the Framework that I may not normally look at.

I know I do not know every thing (read consider myself an expert), but you
did not hear that from me! :-)

Just a thought
Jay
 
Ed,
Property Get/Set statements on the form class would be better, IMO.


What is the sence of that

dim frm as new "dialogform"
frm.showdialog(me)
x = frm.x
frm.close
frm.dispose

It exist mostly only one click from the user.

Why take more effort than necessary with that?

Cor
 
Back
Top