Search
Keyboard Layout

Standard layouts

The component includes two predefined keyboard layouts represented by Default and Extended members of the KeyboardMode enumeration, that can be assigned to the Mode property of VirtualKeyboard. The Default layout is similar to a laptop keyboard without a numpad. Extended mode corresponds to a full keyboard with numpad and navigational key sections.

Custom layouts

You can also create custom layouts represented by KeyboardLayout objects by populating their Keys collections. A KeyboardLayout can be assigned to the TemplateLayout property of VirtualKeyboard to create a language-independent layout whose character labels are automatically set from current locale information. Alternatively, you could set Mode to Custom and specify the location of language-dependent layout files via LayoutsFolder.

While it is possible to create a KeyboardLayout programmatically, it is far easier to use the Keyboard Creator tool installed with the control. You can quickly generate initial layout by choosing a language from the property palette and selecting the Default Layout or Extended Layout commands from Layout menu. You can then remove unnecessary keys, move or resize existing ones or change their labels. You could as well build a layout from scratch by dragging and dropping keys from the various palettes below the menu.

Once you are happy with the result, save the layout to a file. The file can be loaded into the application by either placing it in LayoutsFolder (in which case you should also keep the locale ID part added to the name by the tool), or by calling the static Create method of KeyboardLayout and assigning the result to TemplateLayout:

C#  Copy Code

virtualKeyboard.TemplateLayout = KeyboardLayout.Create("mylayout.xml");

Layout ring

You can define a sequence of keyboard layouts that can be cycled through by setting the LayoutRing property. Add LayoutRingKey to your layouts to let users cycle through the list. Layouts from this list are automatically assigned to TemplateLayout when user presses the LayoutRingKey, or if you call the SelectLayout method from code.

The KeyboardLayout class includes two properties to control the appearance of the LayoutRingKey: Image and Label. One of these is displayed by the key to indicate the next layout in the cycle, following this priority:

1.  If the next layout has a non-null / empty Image property, that image is displayed.
2.  If there is no Image assigned to the layout, but the Label property is set, that text is displayed as key's Content.
3.  If neither Image nor Label is set, the key will display the Unicode keyboard symbol (U+2328) as a fallback.

This code from the LayoutRing sample project demonstrates how to load layouts and populate the LayoutRing:

C#  Copy Code

var lettersLayout = KeyboardLayout.Create("letters.xml");
var numbersLayout = KeyboardLayout.Create("numbers.xml");
var symbolsLayout = KeyboardLayout.Create("symbols.xml");

virtualKeyboard.LayoutRing.Add(lettersLayout);
virtualKeyboard.LayoutRing.Add(numbersLayout);
virtualKeyboard.LayoutRing.Add(symbolsLayout);

virtualKeyboard.SelectLayout(0);