StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



How to implement shortcut keys on...Expand / Collapse
Author
Message
Posted 03/24/2008 6:51:08 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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!
Post #15151
Posted 03/24/2008 7:30:41 PM


StrataFrame Developer

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

Post #15152
Posted 03/25/2008 10:53:46 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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?
Post #15157
Posted 03/25/2008 2:33:09 PM


StrataFrame Developer

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.

Post #15159
Posted 03/25/2008 5:24:36 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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)?
Post #15163
Posted 03/25/2008 5:26:34 PM


StrataFrame Developer

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
Post #15165
Posted 03/25/2008 5:33:53 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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!
Post #15167
Posted 03/25/2008 8:32:47 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 4:17:19 AM
Posts: 4,379, Visits: 4,420
Cool
Post #15171
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 6:49pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.063. 11 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.