- Welcome, Guest. Please Login or Register
MindFusion  
  MindFusion Xamarin Pack beta version includes diagram, chart and calendar controls for Xamarin.Forms. Now beta testing Chart and Gauge components for Java Swing.  
  HomeHelpSearchLoginRegister   
     
     
   
 
Page Index Toggle Pages: 1 Send Topic Print  
Set single key color
Read 453 times

Jim   Offline
YaBB Newbies
*
Posts: 1
I Love MindFusion!


   
     
 
Set single key color
May 20th, 2016 at 8: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?
 
 
 
IP Logged    
 
     

Slavcho   Offline
YaBB Moderator
*****
Posts: 750
Gender: male
tech.support


   
     
 
Re: Set single key color
Reply #1 - May 21st, 2016 at 6: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(); 



Regards,
Slavcho
Mindfusion
 
 
 
IP Logged    
 
     

Slavcho   Offline
YaBB Moderator
*****
Posts: 750
Gender: male
tech.support


   
     
 
Re: Set single key color
Reply #2 - May 21st, 2016 at 7: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;
	}
} 



Regards,
Slavcho
Mindfusion
 
 
 
IP Logged    
 
     
Page Index Toggle Pages: 1 Send Topic Print