StrataFrame Forum

Add shortcutkey to ThemedLinkMenuItem

http://forum.strataframe.net/Topic26835.aspx

By Alex Bibiano González - 4/14/2010

A hava a windows with a ThemedLinkMenu and some ThemedLinkMenuItems.



Is it possible to assign a shortcutkey to a themedlinkmenu item?



Thanks,



Alex B.
By Dustin Taylor - 4/14/2010

That functionality isn't pre-built into the control, but you could certainly handle it manually without much hassle. Just playing around with it myself, the most straight-forward way to do this would seem to be handling the KeyPress event of the form. The only caveat here is that you will need to set the "KeyPreview" property of the form itself to True so that it will catch the keypresses.

Once the KeyPreview property is true, you can handle either the KeyPress or KeyUp events of the form. KeyPress makes things a bit simpler in that you can just test on the character that resulted from the keypress, while KeyUp will give you more finite control on exactly what buttons were pressed on the keyboard (allowing you test for Alt+Key, Shift+Key, Ctrl+Key combinations and the like). 

My test program used the below event handler as the crux of the funcitonality. It's in C#, but is fairly straight forward. Still, if you'd like me to translate to VB, I'd be happy to, just let me know:

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    switch(e.KeyChar)
    {
        case '1':
            {
                themedLinkMenu1.ClickItem("One");
            }
            break;
        case '2':
            {
                themedLinkMenu1.ClickItem("Two");
            }
            break;
        case '3':
            {
                themedLinkMenu1.ClickItem("Three");
            }
            break;
    }
}

You can see there that I am just checking to see if the '1', '2', or '3' keys were pressed and, if so, calling the ThemeLInkMenu's ClickItem method to select the appropriate menu item (which have a Key value of "One", "Two", and "Three" respectively.)