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

Access Keys for buttons - C#

P: n/a
I have posted a similar message and am reposting due to no response.
Basically, I need to know why using the ampersand to indicate an
access key for a button makes it so that simply entering the key alone
selects the button. It should be that the user must press Alt + the
access key. Note that this works also, it is just that I need it to
NOT select the button if the user enters JUST the access key.

My problem is that my application has a set of controls that need to
accept data from the user and whenever I type a key that is also an
access key for one of my buttons, that button gets selected.

I tried to create a new application with a form with just buttons on
it to make sure I didn't do anything to interfere with this mechanism.
I used the ampersand to indicate my access buttons and wrote handlers
for each button to display a popup message. Again, simply pressing the
access key alone selected the button. What is going on here? How can I
get this to work as expected where the user must enter Alt + the
access key?

Any tidbits of info are appreciated.

- Bruce
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Actually, for a button, all you need is the letter to activate a accelerator
key for a button. As far as I know, it's always been that way in Windows.
Fire up any normal windows app, open a dialog with a button with a keyboard
accelerator and hit the key (ex. Run Internet Explorer, go to Tools/Options,
go to the "Privacy" page, hit "v" (for Ad&vanced) and the advanced dialog
pops up). As long as the cursor isn't in a text box or combo box edit area,
it should work that way.

Pete
"BruceR" <br******@msn.com> wrote in message
news:e2**************************@posting.google.c om...
I have posted a similar message and am reposting due to no response.
Basically, I need to know why using the ampersand to indicate an
access key for a button makes it so that simply entering the key alone
selects the button. It should be that the user must press Alt + the
access key. Note that this works also, it is just that I need it to
NOT select the button if the user enters JUST the access key.

My problem is that my application has a set of controls that need to
accept data from the user and whenever I type a key that is also an
access key for one of my buttons, that button gets selected.

I tried to create a new application with a form with just buttons on
it to make sure I didn't do anything to interfere with this mechanism.
I used the ampersand to indicate my access buttons and wrote handlers
for each button to display a popup message. Again, simply pressing the
access key alone selected the button. What is going on here? How can I
get this to work as expected where the user must enter Alt + the
access key?

Any tidbits of info are appreciated.

- Bruce

Nov 15 '05 #2

P: n/a
br******@msn.com (BruceR) wrote in message news:<e2**************************@posting.google. com>...
I have posted a similar message and am reposting due to no response.
Basically, I need to know why using the ampersand to indicate an
access key for a button makes it so that simply entering the key alone
selects the button. It should be that the user must press Alt + the
access key. Note that this works also, it is just that I need it to
NOT select the button if the user enters JUST the access key.

My problem is that my application has a set of controls that need to
accept data from the user and whenever I type a key that is also an
access key for one of my buttons, that button gets selected.

I tried to create a new application with a form with just buttons on
it to make sure I didn't do anything to interfere with this mechanism.
I used the ampersand to indicate my access buttons and wrote handlers
for each button to display a popup message. Again, simply pressing the
access key alone selected the button. What is going on here? How can I
get this to work as expected where the user must enter Alt + the
access key?

Any tidbits of info are appreciated.

- Bruce


Just something else that I am noticing - pressing the Alt key PRIOR TO
entering the key seems to turn off the access key. Ie, each time I
press the Alt key before (not simultaneously) the access key, the
button is not selected. Is there some kind of Alt lock thing going on
here?
Nov 15 '05 #3

P: n/a
Hey Pete,

Thanks for taking the time to respond. Yeah, I know that this is the
default behavior, but for some reason in my C# app, things are
behaving a little strangely. I went ahead and created a simple little
C# application that just had a form with 3 buttons, where I set their
text to be &One, &Two and F&our. Then I wrote click handlers for them
that simply popped up a message box displaying one, two and four
respectively. When I ran the app, I was able to enter, without
simultaneously pressing the Alt key, "o", "t", "f" to select the
corresponding buttons.

I'd invite you to try the same (it only takes a few minutes) and let
me know if you get the same results. If you get it to work as expected
where just selecting the shortcut key alone does NOT select it let me
know.

- Bruce

"Pete Davis" <pd******@hotmail.com> wrote in message news:<49******************************@news.megane tnews.com>...
Actually, for a button, all you need is the letter to activate a accelerator
key for a button. As far as I know, it's always been that way in Windows.
Fire up any normal windows app, open a dialog with a button with a keyboard
accelerator and hit the key (ex. Run Internet Explorer, go to Tools/Options,
go to the "Privacy" page, hit "v" (for Ad&vanced) and the advanced dialog
pops up). As long as the cursor isn't in a text box or combo box edit area,
it should work that way.

Pete
"BruceR" <br******@msn.com> wrote in message
news:e2**************************@posting.google.c om...
I have posted a similar message and am reposting due to no response.
Basically, I need to know why using the ampersand to indicate an
access key for a button makes it so that simply entering the key alone
selects the button. It should be that the user must press Alt + the
access key. Note that this works also, it is just that I need it to
NOT select the button if the user enters JUST the access key.

My problem is that my application has a set of controls that need to
accept data from the user and whenever I type a key that is also an
access key for one of my buttons, that button gets selected.

I tried to create a new application with a form with just buttons on
it to make sure I didn't do anything to interfere with this mechanism.
I used the ampersand to indicate my access buttons and wrote handlers
for each button to display a popup message. Again, simply pressing the
access key alone selected the button. What is going on here? How can I
get this to work as expected where the user must enter Alt + the
access key?

Any tidbits of info are appreciated.

- Bruce

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.