Highlighting active control in a form

WJReid

Active Member
Joined
Jul 26, 2002
Messages
317
Hi All,

Can anyone tell me how to highlight the active control on a form, either the backcolour or the border colour, as you tab through the form?

Thanks for any help in advance

Regards,

Bill
 
Howdy Bill, you can use the enter and exit events to play with the backcolor, e.g.,

<pre>
Private Sub ComboBox1_Enter()
ComboBox1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ComboBox1.BackColor = &H8000000F
End Sub

Private Sub ListBox1_Enter()
ListBox1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub ListBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ListBox1.BackColor = &H8000000F
End Sub

Private Sub OptionButton1_Enter()
OptionButton1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub OptionButton1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
OptionButton1.BackColor = &H8000000F
End Sub</pre>

I just played with a few types. Hope this helps.
 
Upvote 0
On 2002-11-20 20:12, technix wrote:
This is a Neat Idea however when I tried it with a textbox, It did not change color on exit

The following didn't work?<pre>
Private Sub TextBox1_Enter()
TextBox1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.BackColor = &H8000000F
End Sub</pre>

?? Did for me...

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-11-20 20:17
 
Upvote 0
no it doesnt, that changed it to a i dunno salmon type color upon enter however left the color there on exit
 
Upvote 0
What do you mean by exit, did you tab to another control?

If you have a userform where the control is the first in the tab order, closing the form and reopening it is not exiting, it was active when you closed, and active when you opened it.

If you did tab out or click on another control in the same user form, I'm curious as to the failure, e.g., using xl 2000?
 
Upvote 0
On 2002-11-20 20:24, NateO wrote:
What do you mean by exit, did you tab to another control?

If you have a userform where the control is the first in the tab order, closing the form and reopening it is not exiting, it was active when you closed, and active when you opened it.

If you did tab out or click on another control in the same user form, I'm curious as to the failure, e.g., using xl 2000?

Have a Userform with multiple textbox's set it up with textbox1 as your example showed, upon tabing to textbox 2 it stayed salmon colored

using xp with xl 97

Derrick
 
Upvote 0
Actually, and what I just realized is that I used grey in all examples, versus turning the textbox back to white. Will test in xl '97 later tonight (don't have it on me). In the meantime, I'll throw up the following:

<pre>
Private Sub TextBox1_exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.BackColor = -2147483643
End Sub</pre>
 
Upvote 0
This is the mouse over code to change a form button red from green. You need a form and a button to test the code. JSW

Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'On mouse-over, color form back Lt.Blue.
If UserForm1.BackColor = RGB(240, 240, 240) Then _
UserForm1.BackColor = RGB(220, 247, 247)
'On mouse-over, color Button Green.
If CommandButton1.BackColor<> RGB(122, 255, 0) Then _
CommandButton1.BackColor = RGB(122, 255, 100)
End Sub

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'On mouse-over = gone, color form back Lt.Blue.
If UserForm1.BackColor = RGB(240, 240, 240) Then _
UserForm1.BackColor = RGB(220, 247, 247)
'On mouse-over = gone, color Button Red.
If CommandButton1.BackColor<> RGB(255, 0, 0) Then _
CommandButton1.BackColor = RGB(255, 0, 0)
End Sub

Private Sub UserForm_Activate()
'On form open color Back Lt.Blue.
UserForm1.BackColor = RGB(220, 247, 247)
'On form open color Button Bright Red.
If CommandButton1.BackColor<> RGB(255, 0, 0) Then _
CommandButton1.BackColor = RGB(255, 0, 0)
End Sub

Private Sub CommandButton1_Click()
'Deactivate UserForm & color back Lt.Gray.
UserForm1.BackColor = RGB(240, 240, 240)
'Show Msg.
MsgBox Chr(13) & Chr(13) & _
"This could have been any Visual Basic code or Macro!" _
& Chr(13) & Chr(13) & _
"The UserForm ""Button"" has activated this code." _
& Chr(13) & Chr(13) & _
"Any code can be placed here!" _
& Chr(13) & Chr(13) & Chr(13) & Chr(13) & _
" Press ""OK"" when done!" _
& Chr(13)
' This is the click event for UserForm1
'Private Sub UserForm_Click()

'Note: the button will print the userform!
'You may want to comment out the print below!

UserForm1.PrintForm
'End Sub
If UserForm1.BackColor = RGB(240, 240, 240) Then _
UserForm1.BackColor = RGB(220, 247, 247)
End Sub

Private Sub UserForm_Click()
'If UserForm Background is clicked, close form.
UserForm1.Hide
End Sub
This message was edited by Joe Was on 2002-11-20 20:38
 
Upvote 0
Hi NateO,

I had tried the Enter and Exit commands using vbRed and vbWhite, but it worked on entry on some, but not on others and it did not work at all on some. I will try your suggestions this morning.

Thanks to all for their help so far.

Regards,

Bill
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top