Access Keys for buttons - C#

B

BruceR

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
 
P

Pete Davis

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
 
B

BruceR

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?
 
B

BruceR

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top