Link to home
Start Free TrialLog in
Avatar of aot2002
aot2002

asked on

vb .net and focus on textbox

this works ok when using the mouse but doesn't work well when trying to use the tab key pressing through more then 3 textbox's

i want the user to know the color is the focused one.




''''This sub would then be called from each Enter and Leave event:
   Private Sub txtExample1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtExample1.Enter
        FormatTextBox(sender)
    End Sub

    Private Sub txtExample1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtExample1.Leave
        FormatTextBox(sender)
    End Sub




Private Sub FormatTextBox(ByRef txtBoxToFormat As TextBox)
        ' Change the format of a TextBox to highlight which
        ' textbox is currently active (has focus).  Changes
        ' forecolor of the passed TextBox to blue when the box
        ' has focus and black when it does not.
        '
        ' txtBoxToFormat was passed ByRef so changes can be
        ' made directly

        ' Check to see if the textbox currently has
        ' the focus or not
        If txtBoxToFormat.Focused Then
            ' We have focus, set the forecolor to blue
            txtBoxToFormat.ForeColor = Color.Blue
        Else
            ' We do not have focus, set the forecolor to black
            txtBoxToFormat.ForeColor = Color.Black
        End If
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial