what do you have to do in a C# dialog so that it returns to ShowDialog as DialogResult.OK ?

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

what do you have to do in a C# dialog so that it returns to ShowDialog as
DialogResult.OK ?
 
Daniel,

Before the dialog is closed, set the DialogResult property to
DialogResult.OK.

Hope this helps.
 
Hi
Actually, setting the DialogProperty will close the dialog. The other
approach would be to set the OK button DialogRestultProperty to
DialogResult.OK. In this case your don't have to do anything. When the user
clicks on the button the framework will set dialog's DialogResult for you
thus, close the dialog.

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Nicholas Paldino said:
Daniel,

Before the dialog is closed, set the DialogResult property to
DialogResult.OK.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Daniel said:
what do you have to do in a C# dialog so that it returns to ShowDialog as
DialogResult.OK ?
 
For accessibility compliance you may also want to provide a Cancel button
that has a DialogResult property of DialogResult.Cancel, set the dialog Form's
AcceptButton to your Ok button, and the CancelButton to the cancel button.

Then you have all of your bases covered so that users can quickly navigate
and consume your dialog... (PS: Add some Alt+Key accessors to your
buttons, and if you accept user input to your Labels)...


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Stoitcho Goutsev (100) said:
Hi
Actually, setting the DialogProperty will close the dialog. The other approach
would be to set the OK button DialogRestultProperty to DialogResult.OK. In
this case your don't have to do anything. When the user clicks on the button
the framework will set dialog's DialogResult for you thus, close the dialog.

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Nicholas Paldino said:
Daniel,

Before the dialog is closed, set the DialogResult property to
DialogResult.OK.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Daniel said:
what do you have to do in a C# dialog so that it returns to ShowDialog as
DialogResult.OK ?
 
Stoitcho said:
Hi
Actually, setting the DialogProperty will close the dialog. The other
approach would be to set the OK button DialogRestultProperty to
DialogResult.OK. In this case your don't have to do anything. When the user
clicks on the button the framework will set dialog's DialogResult for you
thus, close the dialog.
Hmm, Im still trying to decide on the best methodology here.
Whether to:
a) in the ok button click event set this.DialogResult = DialogResult.Ok
or
b) set DialogResult property of button to Ok

The "different" thing about option b is that you expect the ok buttons
click event to have code in it and when it doesnt, you have to actively
remember that you have a dialogresult property. (New to .NET IIRC).

Having said that, I use option b.

:)
JB
 
Well, that's why you have options. Whatever suits your needs better. But
knowing that Button.DialogResult exsists there should be no problem figuring
out why the button closes the form.
 
Back
Top