Control Background Color

  • Thread starter Thread starter John Lane
  • Start date Start date
J

John Lane

Is there a way entirely change the background color when a control has focus?
That is, the field I have is green backgound with black forecolor. I changed
the background on the fly to red, but the when the field has focus, data in
it was surrounded by black, with red characters. The rest of the field is
red. What I want is the black to go away and leave the white letters.
 
Using the GotFocus and LostFocus events would be my suggestion.

Private Sub ControlName_GotFocus()
Me.ControlName.BackColor = vbBlack
Me.ControlName.ForeColor = vbRed
End Sub

Private Sub ControlName_LostFocus()
Me.ControlName.BackColor = vbGreen
Me.ControlName.ForeColor = vbBlack
End Sub

Change ControlName as appropriate and you can use any numeric color value in
place of the vb colors. I believe the most common colors and be used as I
showed above.
 
The only thing wrong with these solutions is what happens when you put the
cursor (ie., has focus) in the control - you get three colors - the color you
set it to, then a reverse set of colors of the actual string of data - I
guess the form software is trying to highlight and reverse video the
character string - so you can end up with three colors!
 
Back
Top