I have a form with + 50 controls and with key numeric screen to write in only 5 textbox of this form.
I am using this code to write in these textbox using key numeric screen:
Private Sub bt0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt0.Click, bt1.Click, bt2.Click, bt3.Click, bt4.Click, bt5.Click, bt6.Click, bt7.Click, bt8.Click, bt9.Click, btDec.Click
If TypeOf sender Is DevExpress.XtraEditors.SimpleButton Then
txtRefe.Focus()
SendKeys.Send(CType(sender, DevExpress.XtraEditors.SimpleButton).Text)
End If
End Sub
The problem: I need to know which of these 5 textbox had the focus before touching the numerical button
I have seen this code from this post Find out the control with last focus to find last focus:
Private _focusedControl As Control
Private Sub TextBox_GotFocus(ByVal sender As Object, ByVal e As EventArgs)
_focusedControl = DirectCast(sender, Control)
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
If _focusedControl IsNot Nothing Then
'Change the color of the previously-focused textbox
_focusedControl.BackColor = Color.Red
End If
End Sub
But how I do it in a form with + 50 controls (Controls of many types: buttons, checkbox, combos, textbox, etc.) ?