I have multiple textbox in a form. How do I know what textbox the cursor currently is?
Trying to do something like this:
If TextBox2.Focus() = True Then
MessageBox.Show("its in two")
ElseIf TextBox3.Focus = True Then
MessageBox.Show("its in three")
End If
But I think its not working.
Obviously, it will not work if you are calling your code in a
Button_Clickbecause when you click the Button then the focus is itself goes to the Button which you have clicked.You can do two things:
Make a combined Focus event for all TextBoxes and check its Sender object.
OR
Take a global string variable, and set its value at each TextBox_Focus event, then check string value in the button click event.