How do Alt O on OK button

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

How do I fix it so that when the user preses Alt-X a certain button on the
form gets fired?

Also, How do I fix it so that when the esc key is pressed, the form is
closed?
 
Woody,
How do I fix it so that when the user presses Alt-X a certain button on the
form gets fired?
If your form has a menu, you can add hidden menu items that use the Alt-X as
a short cut. Although they are hidden the MenuItem.Click event will still be
raised.

Alternatively if your button has X in the label, you can prefix the X with a
& making the X underscored when displayed. Then when your run the

For example if I set the btnExit.Text property to "E&xit", I can use Alt-X
to click that button.
Also, How do I fix it so that when the esc key is pressed, the form is
closed?

Set the Form.CancelButton property to the button that has Me.Close in its
click event. Alternatively if you set the Button.DialogResult for this
control to DialogResult.Cancel, you do not need to handle the event, the
form will close. (I do this for forms that I use Form.ShowDialog on, I have
not tested with forms I use Form.Show on).

Hope this helps
Jay
 
Hi Woody, in the text of your button, does the letter 'x' appear? If so, you
can prefix 'x' with an ampersand (&):

Text = "E&xit"

The X will appear underlined (unless your using Windows 2000/2003/XP with
the underlining turned off until Alt is pressed), and will respond to Alt+X

Also, if you set the KeyPreview property of your form to True, then you can
trap the Escape key in the KeyPress event of the form.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
 
Change your caption so that a & is right before the HotKey. For example

&OK will make Alt-O fire the button, E&xit will make Alt-X fire the button.
 
Woody Splawn said:
How do I fix it so that when the user preses Alt-X a certain button on the
form gets fired?

In the button's 'Text' property you can specify a mnemonic by putting
the "&" character in front of it: "Cli&X".
Also, How do I fix it so that when the esc key is pressed, the form is
closed?

Set the form's 'CancelButton' property to a button. Then set the
button's 'DialogResult' property.
 
Jay B. Harlow said:
Set the Form.CancelButton property to the button that has Me.Close in its
click event. Alternatively if you set the Button.DialogResult for this
control to DialogResult.Cancel, you do not need to handle the event, the
form will close. (I do this for forms that I use Form.ShowDialog on, I have
not tested with forms I use Form.Show on).

It doesnt seem to work if the form is not shown with ShowDialog. For example, if the form is the
startup form, this will not cause ESC to close it. However, if you set the Forms CancelButton
property, it seems that the ESC key will fire the event of the button specified, no matter how the
form is shown.
 
Rick,
Thanks for confirming that. I normally do not allow Esc to close the main
form just Dialog boxes. I use ShowDialog on Dialog boxes.

Thanks again
Jay
 
A bit off topic, but did you notice that ShowDialog (Modal in VB6) will allow the form to be shown
in the taskbar while its modal? It didnt do that in VB6 without some subclassing.

A nice feature.

Rick
 
Alternatively if your button has X in the label, you can prefix the X with
a
& making the X underscored when displayed. Then when your run the
For example if I set the btnExit.Text property to "E&xit", I can use Alt-X
to click that button.

Thank you.

I tried this in design mode in the properties for the button and this works
but with one catch. The first time I bring the form to the screen I do not
see the underbars. If I press the button or type Alt-X they show but they
do not show when the form is first brought to the screen. I call the dialog
with the following syntax:

iResult = DLG.ShowDialog(Me)
 
Woody,
Its a 'feature' of Windows XP (I am not certain about Windows 2000, I want
to say it has the same 'feature').

The underscore is not displayed until you press Alt, same with the menus.

In Windows XP you can control the option under "Display Properties -
Appearance - Effects - Hide underlined letters for keyboard navigation until
I press the Alt key"

Hope this helps
Jay
 
Hi Jay, It's the same with Windows 2000.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
 
Back
Top