FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Form.accessButton, cancelButton don't work as expected

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
maxter



Joined: 17 May 2006
Posts: 34

PostPosted: Sun Sep 30, 2007 6:40 am    Post subject: Form.accessButton, cancelButton don't work as expected Reply with quote

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
View user's profile Send private message
maxter



Joined: 17 May 2006
Posts: 34

PostPosted: Sun Sep 30, 2007 11:12 pm    Post subject: Reply with quote

Correction: ModalDialog in the example should derive from Form, not Dialog
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Tue Oct 02, 2007 12:52 am    Post subject: Re: Form.accessButton, cancelButton don't work as expected Reply with quote

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
View user's profile Send private message
maxter



Joined: 17 May 2006
Posts: 34

PostPosted: Tue Oct 02, 2007 9:45 am    Post subject: Reply with quote

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
View user's profile Send private message
maxter



Joined: 17 May 2006
Posts: 34

PostPosted: Tue Oct 02, 2007 9:49 am    Post subject: Reply with quote

Not a big issue, really
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Wed Oct 03, 2007 9:00 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group