View previous topic :: View next topic |
Author |
Message |
maxter
Joined: 17 May 2006 Posts: 34
|
Posted: Sun Sep 30, 2007 6:40 am Post subject: Form.accessButton, cancelButton don't work as expected |
|
|
Code: |
class ModalDialog : Dialog
{
this()
{
maximizeBox = false;
minimizeBox = false;
showInTaskbar = false;
formBorderStyle = FormBorderStyle.FIXED_DIALOG;
icon = null;
auto okButton = new Button();
okButton.text = "OK";
okButton.dialogResult = DialogResult.OK;
acceptButton = okButton;
auto cButton = new Button();
cButton.text = "Cancel";
cButton.location = Point(100, 0);
cButton.dialogResult = DialogResult.CANCEL;
cancelButton = cButton;
controls.add(okButton);
controls.add(cButton);
startPosition = FormStartPosition.CENTER_SCREEN;
}
}
|
I'd expect that, after showing this dialog as modal, clicking OK or Cancel (pressing Esc) should close the dialog and appropriate DialogResult should be returned from Form.ShowDialog. |
|
Back to top |
|
|
maxter
Joined: 17 May 2006 Posts: 34
|
Posted: Sun Sep 30, 2007 11:12 pm Post subject: |
|
|
Correction: ModalDialog in the example should derive from Form, not Dialog |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Tue Oct 02, 2007 12:52 am Post subject: Re: Form.accessButton, cancelButton don't work as expected |
|
|
You have to tell it what to do. e.g. add click events to your acceptButton and cancelButton which OK/Cancel and close as necessary. When the user presses Enter or Escape, the appropriate click events are fired automatically. |
|
Back to top |
|
|
maxter
Joined: 17 May 2006 Posts: 34
|
Posted: Tue Oct 02, 2007 9:45 am Post subject: |
|
|
Nope. If you set DialogResult for acceptButton/cancelButton (that is even not needed for cancelButton), you don't have to attach click handlers to those buttons. Clicks on them should be handled by the form automatically. At least, this is the way WinForms work. If you want, you can even do something silly like this:
Button okButton = new Button();
okButton.Text = "OK";
okButton.DialogResult = DialogResult.NO;
AcceptButton = okButton;
When OK is clicked/Enter is pressed while OK button is focused, the form should close (I guess, firing closing and closed) and showDialog should return DialogResult.NO (and dialogResult of the form is also set accordingly) |
|
Back to top |
|
|
maxter
Joined: 17 May 2006 Posts: 34
|
Posted: Tue Oct 02, 2007 9:49 am Post subject: |
|
|
Not a big issue, really |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Wed Oct 03, 2007 9:00 am Post subject: |
|
|
You're right, I never noticed winforms did that. I don't use ShowDialog much so haven't noticed. The current DFL snapshot includes this behavior. Thanks. |
|
Back to top |
|
|
|