By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,685 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,685 IT Pros & Developers. It's quick & easy.

How do Alt O on OK button

P: n/a
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?

Nov 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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

"Woody Splawn" <wo***@splawns.com> wrote in message
news:uM*************@tk2msftngp13.phx.gbl... 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?

Nov 20 '05 #2

P: n/a
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" <wo***@splawns.com> wrote in message news:uM*************@tk2msftngp13.phx.gbl...
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?

Nov 20 '05 #3

P: n/a
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
"Woody Splawn" <wo***@splawns.com> wrote in message
news:uM*************@tk2msftngp13.phx.gbl...
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?

Nov 20 '05 #4

P: n/a
"Woody Splawn" <wo***@splawns.com> scripsit:
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.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

P: n/a

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
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.

Hope this helps
Jay

"Woody Splawn" <wo***@splawns.com> wrote in message
news:uM*************@tk2msftngp13.phx.gbl...
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?


Nov 20 '05 #6

P: n/a
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
"Rick Mogstad" <ri**@NOSPAM.computetosuit.com> wrote in message
news:ei*************@TK2MSFTNGP09.phx.gbl...

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:uh**************@tk2msftngp13.phx.gbl...
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.

Hope this helps
Jay

"Woody Splawn" <wo***@splawns.com> wrote in message
news:uM*************@tk2msftngp13.phx.gbl...
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?



Nov 20 '05 #7

P: n/a
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
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
"Rick Mogstad" <ri**@NOSPAM.computetosuit.com> wrote in message
news:ei*************@TK2MSFTNGP09.phx.gbl...

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message
news:uh**************@tk2msftngp13.phx.gbl...
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.

Hope this helps
Jay

"Woody Splawn" <wo***@splawns.com> wrote in message
news:uM*************@tk2msftngp13.phx.gbl...
> 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?
>
>
>



Nov 20 '05 #8

P: n/a
>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)



Nov 20 '05 #9

P: n/a
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

"Woody Splawn" <wo***@splawns.com> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl...
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-Xto 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)


Nov 20 '05 #10

P: n/a
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
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:#T**************@TK2MSFTNGP10.phx.gbl...
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

"Woody Splawn" <wo***@splawns.com> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl...
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-Xto 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)



Nov 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.