Silverlight Virtual Keyboard in VB.NET

In this article you will see how to create an Virtual Keyboard in Silverlight.
  • 5282
Download Files:
 

Virtual Keyboard: Virtual Keyboard is an On-Screen Keyboard in Silverlight with support for Copying the input to the Clipboard which can then be Pasted into another applicationMy implementation is easily customizable, and you can add as many keyboard layouts as you require, or even customize your own. There are numerous limitations as this is my first attempt to implement such a control.

Example of Virtual Keyboard

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth
="648">
    <Grid x:Name="LayoutRoot" Background="AliceBlue" Height="329" Width="648">
        <Canvas Height="35" Width="643" VerticalAlignment="Top" HorizontalAlignment="Left"Name="box">
            <TextBox Canvas.Left="6" Canvas.Top="6" Height="23" Width="631" Name="store"/>
        </Canvas>
        <Canvas Height="292" Width="648" Margin="0,35,0,0" VerticalAlignment="Top"HorizontalAlignment="Left" Name="Content">
            <StackPanel Height="265" Width="643" Name="Keyboard"/>
        </Canvas>
    </Grid>
</
UserControl>

//MainPage.xaml.vb code

Private Sub Button_KeyPressed(ByVal Value As Object) _
        Handles Me.KeyPressed
        store.Focus()
        store.SelectedText = Value
    End Sub 
    Private Sub UpdateRow(ByRef Row As StackPanelByRef Source As String(,), _
               ByRef Shift As BooleanByRef Count As Integer)
        For Each Item As Button In Row.Children
            For Index As Integer = 0 To Count
                If Shift Then
                    If CStr(Item.Content) = CStr(Source(0, Index)) Then
                        Item.Content = Source(1, Index)
                    End If
                Else
                    If CStr(Item.Content) = CStr(Source(1, Index)) Then
                        Item.Content = Source(0, Index)
                    End If
                End If
            Next
        Next
    End Sub 
    Private Sub Button_Click(ByVal sender As System.Object, _
        ByVal e As System.Windows.RoutedEventArgs)
        Dim _value As New Object
        Dim _command As New Object
        _value = CType(sender, Button).Content
        _command = CType(sender, Button).Tag
        If Not _command Is Nothing Then
            _value = Nothing
            Select Case _command
                Case Sp.BackSpace, Sp.Copy, Sp.Paste, _
                    Sp.Home, Sp.End, Sp.Insert, Sp.Delete
                    RaiseEvent SpPressed(_command)
                Case Sp.Shift
                    _isSft = Not _isSft
                    UpdateRow(_panel1, _row1, _isSft, 12)
                    UpdateRow(_panel2, _row2, _isSft, 11)
                    UpdateRow(_panel3, _row3, _isSft, 11)
                    UpdateRow(_panel4, _row4, _isSft, 10)
                Case Sp.CapsLock
                    _isCps = Not _isCps
                Case Sp.Tab
                    _value = vbTab
                Case Sp.Enter
                    _value = vbCrLf
                Case Sp.Space
                    _value = " "
            End Select
        End If
        If Not _value Is Nothing Then
            If _isCps Xor _isSft Then
                _value = CStr(_value).ToUpper
            Else
                _value = CStr(_value).ToLower
            End If
            RaiseEvent KeyPressed(_value)
        End If
    End 
Sub

Hear I will explain some events to read and learn the hole program please download the source code given at the top of article.

Output Window

1.gif
 

Conclusion

Hope this article would help you to understand how to create an Virtual Keyboard in Silverlight.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.