| | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Yesterday @ 7:31:07 PM Posts: 1,241, Visits: 3,131 |
| I can't figure out how to set a keyboard shortcut on a ToolstripButton (I'm assuming that there is an easy way), so the user can use Clt-S to save for example.
So, is there an easy way to do this? Or do I have to do this the hard way (capturing keyboard input, yada, yada)?
Thanks! |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Today @ 4:17:19 AM Posts: 4,379, Visits: 4,420 |
| Unfortuately a toolstrip button doesn't have the ShortcutKey that a menustrip item does...however, you can do this pretty easy. Just override the ProcessCmdKey method and add your logic:Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean '-- Check for unique keystrokes Select Case keyData Case Keys.Control Or Keys.S '-- Perform save logic End Select Return MyBase.ProcessCmdKey(msg, keyData) End Function |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Yesterday @ 7:31:07 PM Posts: 1,241, Visits: 3,131 |
| | Thanks Trent. I'm assuming this means I'd need to sub-class ToolstripButton, right? If I do that, then I'll need to either manually add buttons via code or manually update the designer file to use my sub-classed button, or is there some other way get a sub-classed toolstrip item into a toolstrip? |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Today @ 4:17:19 AM Posts: 4,379, Visits: 4,420 |
| | Thanks Trent. I'm assuming this means I'd need to sub-class ToolstripButton, right? |
You could, or just add this logic on the form/user control/etc that you want the Ctrl+S to work. You can do the other and create your own type editor, etc. but that is way more work than it is worth...I would just do the other. |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Yesterday @ 7:31:07 PM Posts: 1,241, Visits: 3,131 |
| OK, I'm missing something. 
I don't know how to override the ProcessCmdKey method on the toolstripbutton outside of subclassing it. How do I do it within the form (for example)? |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Today @ 4:17:19 AM Posts: 4,379, Visits: 4,420 |
| Instead of overriding it at the toolstrip or toolstripbutton level, just add the logic in the form or user control that the toolstrip resides in. This way you only have to override the ProcessCmdKey method on the form versus worrying about this in the toolstrip...this is what I generally do and it makes life a lot easier |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Yesterday @ 7:31:07 PM Posts: 1,241, Visits: 3,131 |
| | Ahhhhh...the light bulb went off. I get it. Thanks, that does make sense! |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Today @ 4:17:19 AM Posts: 4,379, Visits: 4,420 |
| Cool |
| |
|
|