Control Background Color

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.
 
S

Scott Whetsell, A.S. - WVSP

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.
 
J

John Lane

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top