I have a form to add a new client to a database. Built in vb.net 2019 Windows Forms. I want to accomplish 2 things:
- When a user enters a textbox, change textbox backcolor to cyan and forecolor to navy to highlight that the user is editing that field.
- When a user leaves a textbox, revert colors back to original but also update the existing text to uppercase.
I have this accomplished already, but, I'm wondering if my method is making unnecessary steps or whether or not it's best practice to add this to the enter and leave event for every single textbox.
Private Sub TextBox1_Enter(sender As Object, e As EventArgs) Handles TextBox1.Enter
TextBox1.BackColor = Color.Cyan
TextBox1.ForeColor = Color.Navy
End Sub
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
TextBox1.BackColor = Color.White
TextBox1.ForeColor = Color.Black
TextBox1.Text = TextBox1.Text.ToUpper
End Sub
Private Sub TextBox2_Enter(sender As Object, e As EventArgs) Handles TextBox2.Enter
TextBox2.BackColor = Color.Cyan
TextBox2.ForeColor = Color.Navy
End Sub
Private Sub TextBox2_Leave(sender As Object, e As EventArgs) Handles TextBox2.Leave
TextBox2.BackColor = Color.White
TextBox2.ForeColor = Color.Black
TextBox2.Text = TextBox2.Text.ToUpper
End Sub
I'm not asking for you to do the work for me- just point me in the right direction, so please don't close this question unless necessary. Legitimately curious if this method is best practice or if there's a more efficient way of handling this.