ff8496abfb91bf20a23a64db591fa997 Hello there! Newbie here! It is my first time to post something here!
Can somebody help me please with my problem on my codes.
I have already build/created a Log In Form but my problem is I created an On-Screen Keyboard which must be use for that Log In Form. I couldn't figure out how to focus/insert the cursor to a certain text box so that I can type in the password and username using that on-screen keyboard. When I press the key buttons the letters** just keep on printing** on both text boxes. All I need to know is how can I input letters using key buttons in each textboxes one at a time. The rest already done. I hope you can help me with this "Log In Form with On-Screen Keyboard"..

All response will be greatly appreciated!
Thanks a lot! And more power to you!! ^__^=

Edited 2 Years Ago by Khyxz

You haven't given any information about your code. I am going to make the following assumptions:

  • Each virtual key is a Button
  • TextBox named: TextBox1
  • TextBox named: TextBox2

There are a few different events that you could probably use, although I don't have a touch-screen to test them:

  • Click
  • Double-click
  • Enter

There may be more.

In my solution, we will use a variable to keep track of which TextBox is selected, since whenever we press a button (virtual key) focus will be on that control.

    'do not define as "New"
    'we will initialize it in form_load

    Dim desiredTextBox As TextBox

In "Load" event of the form, place the following:

        If desiredTextBox Is Nothing Then
            'initialize desiredTextBox
            'set to TextBox1
            desiredTextBox = TextBox1
        End If

So our code is something like this:

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        If desiredTextBox Is Nothing Then
            'initialize desiredTextBox
            'set to TextBox1
            desiredTextBox = TextBox1
        End If
    End Sub

I am going to use the "Enter" event for each TextBox to set the value of "desiredTextBox". This is the way we will keep track based on the last TextBox the user selected.

    Private Sub TextBox2_Enter(sender As System.Object, e As System.EventArgs) Handles TextBox2.Enter
        Console.WriteLine("Textbox2 enter")

        'set desiredTextBox = TextBox2
        desiredTextBox = sender
    End Sub

    Private Sub TextBox1_Enter(sender As System.Object, e As System.EventArgs) Handles TextBox1.Enter
        Console.WriteLine("Textbox1 enter")

        'set desiredTextBox = TextBox1
        desiredTextBox = sender
    End Sub

Now write to "desiredTextBox":

    Private Sub aBtn_Click(sender As System.Object, e As System.EventArgs) Handles aBtn.Click
        desiredTextBox.AppendText("a")
    End Sub

    Private Sub bBtn_Click(sender As System.Object, e As System.EventArgs) Handles bBtn.Click
        desiredTextBox.AppendText("b")
    End Sub

    Private Sub cBtn_Click(sender As System.Object, e As System.EventArgs) Handles cBtn.Click
        desiredTextBox.AppendText("c")
    End Sub

Edited 2 Years Ago by cgeier

TextBox1.Focus will not work, since whenever one presses a virtual key (button) focus will now be on the button, not on the previously selected TextBox.

Thank you very much for all your quick responses!!
Now Everything is working well!
Thanks a lot! Especially to you cgeier!!!
More power to you!

This question has already been answered. Start a new discussion instead.