The MindFusion Forums
Virtual Keyboard Components >> Windows Forms >> Set single key color
https://mindfusion.eu/Forum/YaBB.pl?num=1463772878

Message started by Jim on May 20th, 2016 at 7:34pm

Title: Set single key color
Post by Jim on May 20th, 2016 at 7:34pm
Is possible to change background (also hover & pressed background too) color of a single key on the keyboard at runtime?

Also, how to lock to capslock on a shift doubleclick/doublepress?

Title: Re: Set single key color
Post by Slavcho on May 21st, 2016 at 5:51am
Hi,

At this time painting keys in distinct colors can be done only through a custom KeyTemplate, for example this paints a red Enter key -

[code]
class MyTemplate : KeyTemplate
{
     public MyTemplate()
     {
           defaultBrush = Background;
     }

     GradientBrush defaultBrush;

     public override void Draw(Graphics g, Key key, Mode mode, Font font)
     {
           if (key.Equals(Key.ENTER))
           {
                 Background = new GradientBrush(
                       new List<Color> { Color.Red },
                       new List<float> { 0f }, 0f);
                 base.Draw(g, key, mode, font);
                 Background = defaultBrush;
                 return;
           }

           base.Draw(g, key, mode, font);
     }
}

kb.KeyTemplate = new MyTemplate();[/code]

Regards,
Slavcho
Mindfusion

Title: Re: Set single key color
Post by Slavcho on May 21st, 2016 at 6:05am

Quote:
Also, how to lock to capslock on a shift doubleclick/doublepress?


One way I can see to enable CapsLocks is calling Key.CAPSLOCK.Send method. There's no Key-DoubleClicked event available, instead you might hadle KeyPressed and check the time to determine if it's a double click -

[code]
void OnKeyPressed(object sender, VirtualKeyEventArgs e)
{
     if (e.Key.Equals(Key.SHIFT))
     {
           if (lastClick != null &&
                 DateTime.Now - lastClick.Value < TimeSpan.FromSeconds(0.5))
           {
                 Key.CAPSLOCK.Send(true);
           }

           lastClick = DateTime.Now;
     }
}[/code]

Regards,
Slavcho
Mindfusion

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.