Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing TextBox border refires enter event

Status
Not open for further replies.

JCARPENTER

Programmer
Mar 30, 2000
8
US
Here's what I'm trying to do: I have a form with several TextBox controls. I want whichever control has the focus to also have a different appearance. I've trapped the enter and leave events for the controls and reset the background color and border style within those handlers. It works fine on mouse clicks (that is if I click on a control, it resets to the correct properties, and the one that previously had the focus is also reset). However, when the user tabs among controls, it seems that the focus recurses back to the last control. I've isolated the problem down to the setting of the border style property. Doing that seems to reset the focus to the control I'm trying to exit. The demon follows. Can anybody help?

Thanks,
Jim Carpenter

Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter
Debug.WriteLine("Top of TextBox1_Enter")
TextBox1.BorderStyle = BorderStyle.Fixed3D
TextBox1.BackColor = System.Drawing.Color.FromName("Window")
Debug.WriteLine("Bottom of TextBox1_Enter")
End Sub

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
Debug.WriteLine("Top of TextBox1_Leave")
TextBox1.BorderStyle = BorderStyle.None
TextBox1.BackColor = System.Drawing.Color.FromName("InactiveBorder")
Debug.WriteLine("Bottom of TextBox1_Leave")
End Sub

Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Enter
Debug.WriteLine("Top of TextBox2_Enter")
TextBox2.BorderStyle = BorderStyle.Fixed3D
TextBox2.BackColor = System.Drawing.Color.FromName("Window")
Debug.WriteLine("Bottom of TextBox2_Enter")
End Sub

Private Sub TextBox2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Leave
Debug.WriteLine("Top of TextBox2_Leave")
TextBox2.BorderStyle = BorderStyle.None
TextBox2.BackColor = System.Drawing.Color.FromName("InactiveBorder")
Debug.WriteLine("Bottom of TextBox2_Leave")
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top