locked
Change text color of a ToolStripButton when mouse is over the buttom RRS feed

  • Question

  • Hello, please, How can I can I change the text color of a ToolStripButton when the mouse is over the buttom? how can I detect this situation?? (that the mouse id over the buttom)

    Thanks


    fmorales
    • Moved by CoolDadTx Wednesday, October 5, 2011 5:12 PM Winforms related (From:Visual C# General)
    Wednesday, October 5, 2011 4:36 PM

Answers

  • Hello fmorales,

    Hello, please, How can I can I change the text color of a ToolStripButton when the mouse is over the buttom? how can I detect this situation?? (that the mouse id over the buttom)

    Thanks


    fmorales

    uses the MouseEnter event of the ToolStripButotn to change the text color, and the event to restore mouseLeave

     

      Private Sub ToolStripButton1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.MouseEnter
            Me.ToolStripButton1.ForeColor = Color.Red
        End Sub
    
        Private Sub ToolStripButton1_MouseLeave(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.MouseLeave
            Me.ToolStripButton1.ForeColor = Color.Black
        End Sub

    Regards.


    Carmelo La Monica

    Blog http://community.visual-basic.it/carmelolamonica/

    WordPress http://carmelolamonica.wordpress.com/

    Twitter  http://twitter.com/carmelolamonica

    Wednesday, October 5, 2011 6:08 PM
  • You can create custom toolstrip renderer and custom color table and override all colors and draw methods...

    Example:

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace SharxXTestApplication
    {
        public partial class SharxXForm : Form
        {
            public SharxXForm()
            {
                InitializeComponent();
            }
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
               
                this.toolStrip1.Renderer = new CustomToolStripRendered(new CustomColorTable()); 
            }
        }
    
        //custom toolstrip rendered
        public class CustomToolStripRendered : ToolStripProfessionalRenderer
        {
            public CustomToolStripRendered(CustomColorTable colorTable)
                : base(colorTable)
            { 
            }
    
            //
            // In this class you can override all Draw methods...    
            //
            
            protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
            {
                if (e.Item.Bounds.Contains(e.ToolStrip.PointToClient(Cursor.Position)))
                {
                    e.TextColor = Color.Yellow;
                }
    
                base.OnRenderItemText(e);
            }
        }
    
        //custom color table
        public class CustomColorTable : ProfessionalColorTable
        {
            //
            // In this class you can override all table colors...    
            //
    
            public override Color ButtonSelectedGradientBegin
            {
                get
                {
                    return Color.Orange;
                }
            }
    
            public override Color ButtonSelectedGradientEnd
            {
                get
                {
                    return Color.Blue;
                }
            }
    
            public override Color ButtonSelectedBorder
            {
                get
                {
                    return Color.Red;
                }
            } 
        }
    }
    


     


    • Edited by Adnan Dedic Wednesday, October 5, 2011 6:20 PM
    • Marked as answer by Mike Dos Zhang Sunday, October 9, 2011 8:10 AM
    Wednesday, October 5, 2011 6:12 PM

All replies

  • Hello fmorales,

    Hello, please, How can I can I change the text color of a ToolStripButton when the mouse is over the buttom? how can I detect this situation?? (that the mouse id over the buttom)

    Thanks


    fmorales

    uses the MouseEnter event of the ToolStripButotn to change the text color, and the event to restore mouseLeave

     

      Private Sub ToolStripButton1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.MouseEnter
            Me.ToolStripButton1.ForeColor = Color.Red
        End Sub
    
        Private Sub ToolStripButton1_MouseLeave(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.MouseLeave
            Me.ToolStripButton1.ForeColor = Color.Black
        End Sub

    Regards.


    Carmelo La Monica

    Blog http://community.visual-basic.it/carmelolamonica/

    WordPress http://carmelolamonica.wordpress.com/

    Twitter  http://twitter.com/carmelolamonica

    Wednesday, October 5, 2011 6:08 PM
  • You can create custom toolstrip renderer and custom color table and override all colors and draw methods...

    Example:

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace SharxXTestApplication
    {
        public partial class SharxXForm : Form
        {
            public SharxXForm()
            {
                InitializeComponent();
            }
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
               
                this.toolStrip1.Renderer = new CustomToolStripRendered(new CustomColorTable()); 
            }
        }
    
        //custom toolstrip rendered
        public class CustomToolStripRendered : ToolStripProfessionalRenderer
        {
            public CustomToolStripRendered(CustomColorTable colorTable)
                : base(colorTable)
            { 
            }
    
            //
            // In this class you can override all Draw methods...    
            //
            
            protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
            {
                if (e.Item.Bounds.Contains(e.ToolStrip.PointToClient(Cursor.Position)))
                {
                    e.TextColor = Color.Yellow;
                }
    
                base.OnRenderItemText(e);
            }
        }
    
        //custom color table
        public class CustomColorTable : ProfessionalColorTable
        {
            //
            // In this class you can override all table colors...    
            //
    
            public override Color ButtonSelectedGradientBegin
            {
                get
                {
                    return Color.Orange;
                }
            }
    
            public override Color ButtonSelectedGradientEnd
            {
                get
                {
                    return Color.Blue;
                }
            }
    
            public override Color ButtonSelectedBorder
            {
                get
                {
                    return Color.Red;
                }
            } 
        }
    }
    


     


    • Edited by Adnan Dedic Wednesday, October 5, 2011 6:20 PM
    • Marked as answer by Mike Dos Zhang Sunday, October 9, 2011 8:10 AM
    Wednesday, October 5, 2011 6:12 PM