Hi there, I am creating a application for a touch screen computer/till of course, this means that I have to make a keyboard in my application so you don't have to mess around getting the keyboard out. I have multiple textbox's on my application and would like to know how to make the keys type into the textbox that is focused.

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        NameTextBox.Text = NameTextBox.Text & "M"
    End Sub

^ At the moment I was using this but this only puts the letters into the NameTextbox and also the NameTextbox doesn't appear to be focused..

How would I get the keys to type into the textbox that is focused?

Recommended Answers

All 12 Replies

Hi,

Here's something I made with numbers.

Private Sub Digit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttn1.Click, bttn2.Click, bttn3.Click, _
    bttn4.Click, bttn5.Click, bttn6.Click, bttn7.Click, bttn8.Click, bttn9.Click, bttn0.Click
      
        lblDisplay.Text = lblDisplay.Text + sender.Text
    End Sub

Like you can see it's for numbers.
Add ten buttons and name them like I did, set there text from 1 to 0 and to show the result I used a label with name lblDisplay.

Way you need to set the focus for some textboxes?

Hi, thanks for your reply but I'm not sure if you understood what I ment, I have 3 textbox's on my application each named NameTextbox, DOBTextbox and IDTextbox, I have also made a keyboard below these box's (A-Z, 0-9, backspace and clear) Now, what I need is when I click a textbox when I press a button it puts that letter/number into that focused textbox because at the moment the code I have puts the text into a certian textbox but doesn't keep the textbox focused. (See code above).

Hi,

You can try this:

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        NameTextBox.Text = (NameTextBox.Text & "M")
    End Sub

I really appriciate the help but its not getting me anywhere :/, Do you understand what I'm trying to say? I will try to explain in pictures to see if it helps.

Ok you see here I have clicked inside the ID box, when I click any key I want the letter/number to go inside that box (A Focused box?) but at the moment its going into the "Name Box"


And here I clicked inside the Name box and all numbers and letters go into here..

You see what I'm on about now? When I click inside a box I want that key to go inside there.

You should try this

Dim box As Integer
  Private Sub NNameTextbox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameTextbox.GotFocus
        box = 1

    End Sub
 Private Sub DOBTextbox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DOBTextbox.GotFocus
        box = 2

    End Sub
 
Private Sub IDTextbox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles IDTextbox.GotFocus
        box = 3

    End Sub


    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

if box = 1 then      
  NameTextBox.Text = NameTextBox.Text & "M"
end if
if box = 2 then      
  DOBTextbox.Text = NameTextBox.Text & "M"
end if
if box = 3 then      
  IDTextbox.Text = NameTextBox.Text & "M"
end if
    End Sub

Hi,

meffe beat me on this one ;)

how to do the backspace code?
and the caps lock code?

Hi,

Something like this;

Private Sub NameTextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles NameTextBox.KeyDown
        If e.KeyCode = Keys.Back Then
            MessageBox.Show("You hit the Backkey")
        End If
        If e.KeyCode = Keys.CapsLock Then
            MsgBox("You hit the Capslockkey")
        End If
    End Sub

Thanks Luc001 for the quick respond.
what i mean is, I'm doing on screen keyboard also. if i add a caps lock button which enable caps word i can't seem to solve it

and last question how can i make the "if condition" to check 2 condition at the same time?

the code for the ????? i can't slove.
try boolean and int declare can't get it work


If box = 1 Then
textbox1.Text = textbox1.Text & "A"
???????
textbox1.Text = textbox1.Text & "a"
End If

If box = 2 And caps2 = True Then
textbox2.Text = textbox2.Text & "A"
???????
else
textbox2.Text = textbox2.Text & "a"
End If

I think you are maybe over complicating this I don't think you need to keep track of the box in focus. I suspect all you need for each button is to send in a simulated key stroke.

Private Sub QButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

if caps then Sendkeys.Send(QButton.Text) else sendkeys.send(QButton.Text.toLower)

... nvm i solve already

Private Sub btn_A_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_A.Click

If box = 1 And capsStatus = "On" Then
textbox1.Text = textbox1.Text & "A"

ElseIf box = 2 And capsStatus = "On" Then
textbox2.Text = textbox2.Text & "A"

ElseIf box = 1 And capsStatus = "Off" Then
textbox1.Text = textbox1.Text & "a"
Else
textbox2.Text = textbox2.Text & "a"
End If

End Sub

You should try this

Dim box As Integer
  Private Sub NNameTextbox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameTextbox.GotFocus
        box = 1

    End Sub
 Private Sub DOBTextbox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DOBTextbox.GotFocus
        box = 2

    End Sub
 
Private Sub IDTextbox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles IDTextbox.GotFocus
        box = 3

    End Sub


    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

if box = 1 then      
  NameTextBox.Text = NameTextBox.Text & "M"
end if
if box = 2 then      
  DOBTextbox.Text = NameTextBox.Text & "M"
end if
if box = 3 then      
  IDTextbox.Text = NameTextBox.Text & "M"
end if
    End Sub

Hello my frinds .
I am newby in vb and i want to ask something .
i develope a touch screen app.
i open my touch screen keboard with different winform and my problem is only in the first text box i can write in the other form . any help please ???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.