12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

298 Day 8<br />

NOTE<br />

NOTE<br />

NOTE<br />

The Default Property<br />

The Default property is another key property of buttons. W<strong>in</strong>dows has a standard<br />

mechanism for deal<strong>in</strong>g with dialog boxes. One of the features of this mechanism is as follows:<br />

If a control other than a button has keyboard focus and the user presses the Enter key on the<br />

keyboard, the dialog box will behave as if the user had clicked the default button. The default<br />

button is the button that has the BS_DEFPUSHBUTTON style set (usually the OK button). This<br />

feature has been the bane of programmers and the curse of data-entry personnel for years. The<br />

Default property is used to set a button as the default button for a form. The default value<br />

for this property is false. To make a button the default button, set its Default property to<br />

true. If you don’t specifically set any button’s Default property to true, the form will not<br />

close when the user presses the Enter key.<br />

When the user closes the form by press<strong>in</strong>g the Enter key, the OnClick<br />

handler of the default button (if one exists) will be called before the<br />

form closes.<br />

The Cancel Property<br />

The Cancel property works with the Esc key <strong>in</strong> much the same way as the Default property<br />

works with the Enter key. When the user presses the Esc key to close a form, the return value<br />

from ShowModal() will be the ModalResult value of the button whose Cancel property is set<br />

to true. If no button has its Cancel property set to true, mrCancel will be returned if the user<br />

uses the Esc key to close the form (mrCancel is equal to 2; see Table 8.7).<br />

Clos<strong>in</strong>g a form by click<strong>in</strong>g the system close box or by press<strong>in</strong>g Alt+F4<br />

will result <strong>in</strong> mrCancel be<strong>in</strong>g returned from ShowModal() as you would<br />

expect. Press<strong>in</strong>g the Esc key, however, will result <strong>in</strong> a return value of<br />

the ModalResult property be<strong>in</strong>g set to whatever button has the Cancel<br />

property set to true. The OnClick handler for the Cancel button will be<br />

called before the form closes. No OnClick handler is called if the user<br />

uses the system close box or Alt+F4 to close the form. Be sure to<br />

anticipate the different ways users might use (or abuse) your forms.<br />

You may have more than one button with a Default property set to<br />

true. Likewise, you may have more than one button with the Cancel

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!