Better solution for making on-screen keyboard

萝らか妹 提交于 2019-12-02 07:16:52

Why you even needs to write code? As a better and more logical solution you can use the on-screen keyboard application that comes with windows for this purpose:

System.Diagnostics.Process.Start("osk.exe");

Yes, there is. You can set the "Tag"-Property of the Controls manually, then apply the same Handler to all the Click-Events and add the Content of the "Tag" to the TextBox accordingly.

TextBox.Text += (string)(((Button)sender).Tag);

Set the tag property for each button in the designer to the corresponding text. Then, under your form initialize event, add a single event handler for all the buttons. In tastaturasIevade method use the tag property of the button.

Simple example using .Text of the keys. A .Tag="c" is a character. More complex tags can be used for logic flow. btnQ is the only named button in the simple example. Shift has a dedicated click event.

Sub ShiftCaseLower()
    For Each c As Control In FlowLayoutPanel1.Controls
        If c.Tag = "c" Then c.Text = c.Text.ToLower
    Next
End Sub
Sub ShiftCaseUpper()
    For Each c As Control In FlowLayoutPanel1.Controls
        If c.Tag = "c" Then c.Text = c.Text.ToUpper
    Next
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, btnQ.Click
    ' all "key" click events handled here
    TextBox1.AppendText(sender.text)
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
    ' Shift key
    If Asc(btnQ.Text) = Asc("Q") Then
        ShiftCaseLower()
    Else
        ShiftCaseUpper()
    End If
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!