
Setting BorderStyle fies Enter event
I'm trying to change the appearance of TextBoxes on the
fly. I want only the control with the current focus to
appear as a "standard" TextBox. All others should blend
into the form. I've set up event handlers for the various
TextBoxes where I set the BorderStyle and BackGround color
of the control based on whether we're Entering or Leaving
the control. It works fine as long as the user clicks on
the controls, but when you use the tab key, things get a
little funky. It that case setting the BorderColor of the
control seems to be refiring the Enter event. The focus
never goes to the next control. The code folows(I've
coded a generic handler for the Leave and Enter events,
but the behavior is exactly the same even if the code is
all in separate handlers).
Is there any way out of this?
Thanks,
Jim
Private Sub TextBox1_Enter(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TextBox1.Enter
EditControl_Enter(CType(sender, TextBox))
End Sub
Private Sub TextBox1_Leave(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TextBox1.Leave
EditControl_Leave(CType(sender, TextBox))
End Sub
Private Sub TextBox2_Enter(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TextBox2.Enter
EditControl_Enter(CType(sender, TextBox))
End Sub
Private Sub TextBox2_Leave(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TextBox2.Leave
EditControl_Leave(CType(sender, TextBox))
End Sub
Private Sub EditControl_Leave(ByVal TB As TextBox)
Debug.WriteLine("Top of EditControl_Leave: " &
TB.Name)
TB.BorderStyle = BorderStyle.None
Debug.WriteLine("Middle of EditControl_Leave: " &
TB.Name)
TB.BackColor = Me.BackColor
Debug.WriteLine("Bottom of EditControl_Leave: " &
TB.Name)
End Sub
Private Sub EditControl_Enter(ByVal TB As TextBox)
Debug.WriteLine("Top of EditControl_Enter: " &
TB.Name)
TB.BorderStyle = BorderStyle.Fixed3D
Debug.WriteLine("Middle of EditControl_Enter: " &
TB.Name)
TB.BackColor = System.Drawing.Color.FromName
("Window")
Debug.WriteLine("Bottom of EditControl_Enter: " &
TB.Name)
End Sub