שתף באמצעות


ToolStrip BUTTON HOVER COLOR

Question

Monday, May 18, 2009 7:30 AM

I am having trouble with the HOVER of Buttons on a ToolStrip control under Vista. My ToolStrip control has a nice black background but I have no way of changing the HOVER COLOR for my button - it permanently keeps the default bluish Vista System colors. I've tried already to set the ToolStripButton1.BackgroundColor to something else on MouseEnter or MouseHover but yet this settings have no effect. Does anybody know of a solution? At best I would like to use a BackgroundImage for the ToolStripButton itself but I am already happy if I am only able to set a different Button.BorderColor / Button.BackgroundColor.

All replies (6)

Monday, May 25, 2009 5:10 AM ✅Answered | 1 vote

Hi Junner2003,

There is not an easy way to change the hover color since it is a system behavior.
Here is an article about change hover color: http://www.codeproject.com/KB/buttons/zhaocolorbutton.aspx
It juse use pen to change hover color:

    case _States.MouseOver:
        brush = new LinearGradientBrush(newRect, 
              _HoverColorA, _HoverColorB, mode);
        switch (_ButtonStyle)
        {
            case ButtonStyles.Rectangle:
                e.Graphics.FillRectangle(brush, newRect);
                e.Graphics.DrawRectangle(new 
                     Pen(_HoverBorderColor, 1), newRect);
                break;
            case ButtonStyles.Ellipse:
                e.Graphics.FillEllipse(brush, newRect);
                e.Graphics.DrawEllipse(new 
                   Pen(_HoverBorderColor, 1), newRect);
                break;

        }
        e.Graphics.DrawString(this.Text, base.Font, 
          new SolidBrush(base.ForeColor), textX, textY);
        break;

To custmize the render mode, you can refer to this article: http://www.codeproject.com/KB/toolbars/customtoolstrip.aspx
You can add you cusmize property to its CustomToolStripColorTable class.
For more properties that you can custmize, read this : http://msdn.microsoft.com/en-us/library/system.windows.forms.professionalcolortable_properties(VS.80).aspx

Best Regards

Yichun Feng

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


Wednesday, May 20, 2009 5:31 AM

Hi Junner2003,

Welcome to VB forum.

Actually, the BackgroundColor works in vista.

    Private Sub ToolStripButton1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.MouseHover
        ToolStripButton1.BackColor = Color.Black
    End Sub

Before mousehover:

After mousehover:

If you still have problem, please post the pictures of the button.
How to add image:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/33bf2119-5f56-40b2-a689-d437ec09e550

 

Best Regards

Yichun Feng

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


Wednesday, May 20, 2009 6:06 AM

Hi Yichun Feng,

Actually, my ToolStrip is automatically generated by my DataBindingSource (BindingSourceNavigator) after pulling over some database fields from my db to the form. Can it be that the BindingSourceNavigator ToolStrip differs in behavior compared to a standard ToolStrip? It just does not accept any hover colors; well, it accepts them but they have no influence on the Hover behavior.

For the time being I've set my ToolStrip's RendererMode to SYSTEM - this way I get at least a "glass effect" rather than the lightblue highlight.


Monday, May 25, 2009 1:12 PM

Thanks a lot!
I thought it might not be easy but heh, at least it is possible! :-)


Thursday, July 15, 2010 5:51 PM

Hi

Is there anyway i can apply this in VB.Net?


Thursday, March 22, 2012 9:34 PM

For anyone that runs into this, you need to handle the MouseHover event in your ToolStripItem as Yichun Feng said.  In the event handler, set the BackColor property to the highlight color you would like, and then make sure you call Invalidate() on your ToolStripItem.  This will force a redraw of it, causing the color to show up.  Without the Invalidate, you won't see the color.