PC Review


Reply
Thread Tools Rate Thread

Accelerator keys

 
 
Alex
Guest
Posts: n/a
 
      3rd Sep 2009
I have .Net windows forms with buttons. Each button has been assigned
with accelerator key. But once form opens the accelerator keys works
even if the ALT key is not pressed. For example for Button "&Save"
pressing the S key without ALT fires the button click.
Is there any way to supress this behaviour? Or this is standard for
Windows Forms?
 
Reply With Quote
 
 
 
 
Scott Seligman
Guest
Posts: n/a
 
      4th Sep 2009
Alex <(E-Mail Removed)> wrote:
>
>I have .Net windows forms with buttons. Each button has been assigned
>with accelerator key. But once form opens the accelerator keys works
>even if the ALT key is not pressed. For example for Button "&Save"
>pressing the S key without ALT fires the button click.
>Is there any way to supress this behaviour? Or this is standard for
>Windows Forms?


It's standard for Windows dialogs.

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
Democracy must be something more than two wolves and a sheep voting
on what to have for dinner.
-- James Bovard in Lost Rights: The Destruction of American Liberty
 
Reply With Quote
 
Jeff Johnson
Guest
Posts: n/a
 
      4th Sep 2009
"Alex" <(E-Mail Removed)> wrote in message
news:275e4898-b2da-43dc-a895-(E-Mail Removed)...

>I have .Net windows forms with buttons. Each button has been assigned
> with accelerator key. But once form opens the accelerator keys works
> even if the ALT key is not pressed. For example for Button "&Save"
> pressing the S key without ALT fires the button click.
> Is there any way to supress this behaviour? Or this is standard for
> Windows Forms?


This will work if you have multiple buttons on the form and one of those
buttons has keyboard focus. Technically Windows has the concept of "groups,"
which button controls can be in (and remember, radio buttons and check boxes
are also buttons). The idea is to provide easy keyboard access to this group
of buttons, allowing you to, for example, simply hit Y or N in a Yes/No
dialog box.

Groups are defined by setting the WS_GROUP style on the FIRST item in the
group. The group then continues until the next control that has the WS_GROUP
style, which starts a new group. The accelerators only work within a group.
Here's the MSDN definition of the style:

################
WS_GROUP
Specifies the first control of a group of controls. The group consists of
this first control and all controls defined after it, up to the next control
with the WS_GROUP style. The first control in each group usually has the
WS_TABSTOP style so that the user can move from group to group. The user can
subsequently change the keyboard focus from one control in the group to the
next control in the group by using the direction keys.
You can turn this style on and off to change dialog box navigation. To
change this style after a window has been created, use SetWindowLong.
################

Note that the description above talks about arrow keys but fails to mention
accelerators. Good job, MSDN.

Now, here's the trick: for some reason, Microsoft seems to have decided that
this particular style isn't important enough to expose to us lowly non-C[++]
developers, because there is no easy way to set it in Windows Forms, nor was
it ever available in VB. You have to call SetWindowLong() directly to fiddle
with it. So as long as your buttons are all in the same container, you can
control grouping without P/Invoke. If it's really bugging you and you don't
want to call Windows API functions, you could put each button in a
borderless group box.


 
Reply With Quote
 
Jeff Johnson
Guest
Posts: n/a
 
      4th Sep 2009
"Jeff Johnson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> So as long as your buttons are all in the same container, you


CAN'T

> control grouping without P/Invoke.


Stupid typos.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accelerator keys Albert Browne Microsoft Excel Programming 1 20th Sep 2008 01:49 PM
Accelerator Keys news.microsoft.com Microsoft C# .NET 1 8th Oct 2007 09:15 PM
accelerator Keys =?Utf-8?B?cHJpY2U=?= Windows XP General 5 17th Aug 2007 03:33 PM
Accelerator Keys Nigel Microsoft Excel Programming 1 21st Oct 2003 10:13 PM
accelerator keys Richard Microsoft Dot NET 2 9th Sep 2003 04:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:31 PM.