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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COMMAND BUTTON TEST COLOR CHANGE DURING MOUSE-OVER

Status
Not open for further replies.

Hiccup

Programmer
Jan 15, 2003
266
US
Excuse me all for repeating this thread, but I couldn't get your suggestions to work.

In VB6, I would like the text on a Command Button to change color (ForeColor) when the mouse passes over it, then change back to the original color when the mouse moves off of it.

Any code suggestions?

Thanks in advanced!!

Ed "Hiccup" Hicks
ed.hicks@wcg.com
 
How big is the program? One way could be in the CommandButton_MouseMove to set the Forecolor to the color you want when the mouse is on it. Then on the Form_MouseMove set the ForeColor back to it's original color.

However, this means that the color will always be setting itself everytime the user moves the mouse. Not the best method, but it's a quick fix and since I'm not sure what the other suggestions where, it's the best I can come up with.

-Nate
 
If you were to use the MouseMove event, I think I'd use it for the Form instead of the button. The reasoning for that is if you move your moust over the button fast enough, then the command button won't realize that the pointer has moved on or off the button and could be set to the wrong color.

That's more going on though since it would be checking over the entire form... you could always put up a condition to check the location so it only changes the color when it moves in or out of a coordinate range. That might help a little?

Either way, this certainly can't be a good solution. Hopefully someone has a better idea.

--
Jonathan
 
In your previous post, CCLINT had a good suggestion with a check box.

Then use this code:

Private Sub Check1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Check1.ForeColor = RGB(255, 255, 255)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Check1.ForeColor = RGB(0, 0, 0)
End Sub


Rob
 
A simple solution is to use the fontbold property in the mouse move events.

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.FontBold = True
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.FontBold = False
End Sub

Because there is no forecolor property for the command button.

Another thing you could try is making 2 graphics of the command button the way you want it to look in each case.

 
What has been posted is indeed valuable and useful information, but it is not sufficient to fully achieve the objective. It's not necessarily the Form_MouseMove event that is needed to return the button to its normal stated, but rather it's the container of the button that you need to look at. You can certainly design the form so that the form is always the container, but you can also put the button inside of a frame, or a grid, or any other control which can act as a container. If you do so, then you'll need the container control's MouseMove event as well. You also have to insure that sufficient white space exists around the button in order to catch the container's mouse move event.

You also need to handle the focus issue. To see what I mean, place the cursor in a text field, and then move the mouse over a button. No doubt the button duly highlights itself. Now using the TAB key, tab to a button that is not highlighted, and press the ENTER key. Which button's event is triggered, the Highlighted button, or the button with the focus? You may now have a confused user on your hands.

I also wonder, and this I haven't checked out, what will happen if the application loses focus, the move is moved, and then when the application comes back in focus, by clicking on the window title, what is the state of the button's display, with respect to the cursor location, and which control has focus.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The code presented in thread222-416091 eliminates most of the issues raised by CajunCenturion (but is only a solution to the RollOver part of this question, not the changing of the forecolor for which CCLINT's checkbox solution is probably the neatest workaround)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top