Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Changing appearance of keyboard keys (Read 8801 times)
Chris M
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 17
Joined: Oct 7th, 2014
Changing appearance of keyboard keys
May 10th, 2016 at 2:39pm
Print Post  
I see from http://www.mindfusion.eu/onlinehelp/keyboard.winforms/index.htm?Appearance_3.htm the keys appearance can be changed via the KeyTemplate class or via a custom theme XML file.

Can you send me a sample XML for creating a custom theme?

It seems as though the Keyboard Creator should have a key appearance editor and the ability to output a theme XML file...
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3204
Joined: Oct 19th, 2005
Re: Changing appearance of keyboard keys
Reply #1 - May 11th, 2016 at 8:07am
Print Post  
You can find one installed with the control at Samples\src\Common\CustomTheme.xml location.

Quote:
It seems as though the Keyboard Creator should have a key appearance editor and the ability to output a theme XML file...


I agree... We have theme editors for most controls from the pack and will probably create one for the keyboard too for next version.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Chris M
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 17
Joined: Oct 7th, 2014
Re: Changing appearance of keyboard keys
Reply #2 - May 16th, 2016 at 3:36pm
Print Post  
Thank you. I modified the XML theme. See Virtual_Keyboard.jpg for current keyboard.. Is there a way to modify what is displayed within the key itself (without using an image) such as font, font size, position of character, etc.?

Is there a way to make it look like the sample in Keyboard_Sample.jpg?
  

Virtual_Keyboard.jpg ( 8 KB | 230 Downloads )
Virtual_Keyboard.jpg
Keyboard_Sample.jpg ( 8 KB | 228 Downloads )
Keyboard_Sample.jpg
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3204
Joined: Oct 19th, 2005
Re: Changing appearance of keyboard keys
Reply #3 - May 17th, 2016 at 8:56am
Print Post  
Hi,

Characters are rendered using VirtualKeyboard.Font property. The font size specified there will match only if the control's size is equal to the size (Width and Height properties) specified in KeyboardLayout. Otherwise the keyboard is rendered using a global scale transform, and you might have to multiply keyboard.Font.Size by inverse scale if you need the apparent font size to stay fixed regardless of control's dimensions.

From what I can see in the code, at this time there are two ways to draw a single centered character -

- set the RegularKey.Content property to a string containing just the key character. In that case the string is always drawn centered. This will disable caps/shift handling though and might have some other unforeseen consequences, as Content characters are sent to focused window in a completely different way (WM_CHAR messages rather than the usual down / up + virtual key code simulation).

- or derive from the KeyTemplate class, assign its instance to VirtualKeyboard.KeyTemplate and override KeyTemplate.Draw. You'd then be able to call Graphics.DrawString to draw the character at whatever position you need for keys you'd like to customize, and call base method for ones that should have default appearance.

Regards,
Slavcho
Mindfusion
« Last Edit: May 17th, 2016 at 11:21am by Slavcho »  
Back to top
 
IP Logged
 
Chris M
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 17
Joined: Oct 7th, 2014
Re: Changing appearance of keyboard keys
Reply #4 - May 18th, 2016 at 3:56pm
Print Post  
The first option doesn't work because, like you said, the shift/caps handling causes issues.

Can you further explain option two?

I would just like a keyboard where all letters are lower case and centered and when shift is pressed all letters become upper case. This is the way practically all phones and tablets interact. Is something like this doable with the current keyboard version?
  

Keyboard_Sample__Shift_Pressed_.jpg ( 14 KB | 232 Downloads )
Keyboard_Sample__Shift_Pressed_.jpg
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3204
Joined: Oct 19th, 2005
Re: Changing appearance of keyboard keys
Reply #5 - May 18th, 2016 at 5:03pm
Print Post  
Here's an easy way to implement it -

Code
Select All
class MyTemplate : KeyTemplate
{
	public override void Draw(Graphics g, Key key, Mode mode, Font font)
	{
		var regKey = key as RegularKey;
		if (regKey != null)
		{
			var replacement = (RegularKey)regKey.Clone();
			replacement.Content = VirtualKeyboard.ShiftLocked ?
				regKey.CapitalCase : regKey.LowerCase;
			base.Draw(g, replacement, mode, font);
			return;
		}

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



You could as well draw the label directly with lower-level Graphics API -

Code
Select All
var label = VirtualKeyboard.ShiftLocked ?
	regKey.CapitalCase : regKey.LowerCase;
g.DrawString(
	label, font, Brushes.Black,
	(float)(key.Left + key.Width / 2),
	(float)(key.Top + key.Height / 2),
	StringFormat.GenericDefault);
 



In latter case you'll also have to implement drawing code for the keys' background and borders.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Chris M
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 17
Joined: Oct 7th, 2014
Re: Changing appearance of keyboard keys
Reply #6 - May 19th, 2016 at 1:35pm
Print Post  

Thank you very much! That was very helpful.

There does seem to be a small issue with the punctuation marks. The regular letters have correct lower and upper case (See Watch 1.jpg). However, the punctuation marks don't seem to. For example, the "/" key is the "lower case" of that button. But when Shift is pressed along with the "/" the result is a "?" (on a EN-US qwerty keyboard anyway). So shouldn't the CapitalCase of the "/" key be "?" (See Watch 2.jpg)?
  

Watch_1.jpg ( 8 KB | 243 Downloads )
Watch_1.jpg
Watch_2.jpg ( 7 KB | 234 Downloads )
Watch_2.jpg
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3204
Joined: Oct 19th, 2005
Re: Changing appearance of keyboard keys
Reply #7 - May 19th, 2016 at 3:15pm
Print Post  
My bad - use regKey.UpperCase instead of CapitalCase property.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Chris M
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 17
Joined: Oct 7th, 2014
Re: Changing appearance of keyboard keys
Reply #8 - May 19th, 2016 at 5:50pm
Print Post  
Ha, didn't even notice that property down there.

Thanks!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint