locked
How do I change the style of a menustrip RRS feed

  • Question

  • I've tried rendermode and it doesnt do anything noticable
    Saturday, January 9, 2010 9:44 PM

Answers

  • You can and you should use the Renderer Property.
    Here's a sample:

        //Add this to the bottom of your form. (After your class ends)
        class CustomProfessionalColors : ProfessionalColorTable
        {
            public override Color ToolStripGradientBegin
            { get { return Color.BlueViolet; } }
    
            public override Color ToolStripGradientMiddle
            { get { return Color.CadetBlue; } }
    
            public override Color ToolStripGradientEnd
            { get { return Color.CornflowerBlue; } }
    
            public override Color MenuStripGradientBegin
            { get { return Color.Salmon; } }
    
            public override Color MenuStripGradientEnd
            { get { return Color.OrangeRed; } }
        }
    
        //After that, put this code in the constructor of your form.
            public TempForm()
            {
                InitializeComponent();
                menuStrip1.Renderer = new ToolStripProfessionalRenderer(new CustomProfessionalColors());
            }

    Hope it helps.

    CPU: Core2 Due E7300 2.66GHz, RAM: 4GB DDR2, OS:Windows 7 Ultimate, HDD: 1TB SATA II, VGA: 1GB ATI , Compiler: VS 2008 Pro Sp1
    • Marked as answer by Harry Zhu Friday, January 15, 2010 3:03 AM
    Sunday, January 10, 2010 8:47 AM
  • Check this as well:
    http://www.codeproject.com/KB/toolbars/customtoolstrip.aspx

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    • Marked as answer by Harry Zhu Friday, January 15, 2010 3:04 AM
    Tuesday, January 12, 2010 9:14 AM
  • Hi,

    The RenderMode will change painting styles to be applied to the menuStrip control.

    System Indicates the use of a ToolStripSystemRenderer to Paint.
    Professional indicates the use of a ToolStripProfessionalRenderer to paint.

    Please try the code below to see the effects of setting the property:
            private void button1_Click(object sender, EventArgs e)
            {
                menuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
            }
            private void button2_Click(object sender, EventArgs e)
            {
                menuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            }

    We can also derive from ToolStripSystemRenderer or ToolStripProfessionalRenderer class to create our own renderer and set the menuStrip's renderer property to an instance of the derived class.
    Here is an example :
     How to: Create a Professionally Styled ToolStrip Control.

    Harry

    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.
    • Marked as answer by Harry Zhu Friday, January 15, 2010 3:04 AM
    Tuesday, January 12, 2010 9:32 AM

All replies

  • Put some code, Please.
    With best regards, Yasser Zamani
    Sunday, January 10, 2010 5:49 AM
  • You can and you should use the Renderer Property.
    Here's a sample:

        //Add this to the bottom of your form. (After your class ends)
        class CustomProfessionalColors : ProfessionalColorTable
        {
            public override Color ToolStripGradientBegin
            { get { return Color.BlueViolet; } }
    
            public override Color ToolStripGradientMiddle
            { get { return Color.CadetBlue; } }
    
            public override Color ToolStripGradientEnd
            { get { return Color.CornflowerBlue; } }
    
            public override Color MenuStripGradientBegin
            { get { return Color.Salmon; } }
    
            public override Color MenuStripGradientEnd
            { get { return Color.OrangeRed; } }
        }
    
        //After that, put this code in the constructor of your form.
            public TempForm()
            {
                InitializeComponent();
                menuStrip1.Renderer = new ToolStripProfessionalRenderer(new CustomProfessionalColors());
            }

    Hope it helps.

    CPU: Core2 Due E7300 2.66GHz, RAM: 4GB DDR2, OS:Windows 7 Ultimate, HDD: 1TB SATA II, VGA: 1GB ATI , Compiler: VS 2008 Pro Sp1
    • Marked as answer by Harry Zhu Friday, January 15, 2010 3:03 AM
    Sunday, January 10, 2010 8:47 AM
  • Hi,

    ToolStripGradientBegin,ToolStripGradientMiddle,ToolStripGradientEnd are for toolStrip control.
    MenuStripGradientBegin,MenuStripGradientEnd are for menuStrip.

    If you want to change the color of MenuItem, you might want to override the following properties:


            //
            // Summary:
            //     Gets the border color to use with a System.Windows.Forms.ToolStripMenuItem.
            //
            // Returns:
            //     A System.Drawing.Color that is the border color to use with a System.Windows.Forms.ToolStripMenuItem.
            public virtual Color MenuItemBorder { get; }
            //
            // Summary:
            //     Gets the starting color of the gradient used when a top-level System.Windows.Forms.ToolStripMenuItem
            //     is pressed.
            //
            // Returns:
            //     A System.Drawing.Color that is the starting color of the gradient used when
            //     a top-level System.Windows.Forms.ToolStripMenuItem is pressed.
            public virtual Color MenuItemPressedGradientBegin { get; }
            //
            // Summary:
            //     Gets the end color of the gradient used when a top-level System.Windows.Forms.ToolStripMenuItem
            //     is pressed.
            //
            // Returns:
            //     A System.Drawing.Color that is the end color of the gradient used when a
            //     top-level System.Windows.Forms.ToolStripMenuItem is pressed.
            public virtual Color MenuItemPressedGradientEnd { get; }
            //
            // Summary:
            //     Gets the middle color of the gradient used when a top-level System.Windows.Forms.ToolStripMenuItem
            //     is pressed.
            //
            // Returns:
            //     A System.Drawing.Color that is the middle color of the gradient used when
            //     a top-level System.Windows.Forms.ToolStripMenuItem is pressed.
            public virtual Color MenuItemPressedGradientMiddle { get; }
            //
            // Summary:
            //     Gets the solid color to use when a System.Windows.Forms.ToolStripMenuItem
            //     other than the top-level System.Windows.Forms.ToolStripMenuItem is selected.
            //
            // Returns:
            //     A System.Drawing.Color that is the solid color to use when a System.Windows.Forms.ToolStripMenuItem
            //     other than the top-level System.Windows.Forms.ToolStripMenuItem is selected.
            public virtual Color MenuItemSelected { get; }
            //
            // Summary:
            //     Gets the starting color of the gradient used when the System.Windows.Forms.ToolStripMenuItem
            //     is selected.
            //
            // Returns:
            //     A System.Drawing.Color that is the starting color of the gradient used when
            //     the System.Windows.Forms.ToolStripMenuItem is selected.
            public virtual Color MenuItemSelectedGradientBegin { get; }
            //
            // Summary:
            //     Gets the end color of the gradient used when the System.Windows.Forms.ToolStripMenuItem
            //     is selected.
            //
            // Returns:
            //     A System.Drawing.Color that is the end color of the gradient used when the
            //     System.Windows.Forms.ToolStripMenuItem is selected.
            public virtual Color MenuItemSelectedGradientEnd { get; }




    and here is an example :
      class CustomProfessionalColors : ProfessionalColorTable
            {
                public override Color MenuItemSelectedGradientBegin
                { get { return Color.White; } }
                public override Color MenuItemSelectedGradientEnd
                { get { return Color.Yellow; } }
             }

    Harry


     
    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.
    Tuesday, January 12, 2010 8:51 AM
  • Check this as well:
    http://www.codeproject.com/KB/toolbars/customtoolstrip.aspx

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    • Marked as answer by Harry Zhu Friday, January 15, 2010 3:04 AM
    Tuesday, January 12, 2010 9:14 AM
  • Hi,

    The RenderMode will change painting styles to be applied to the menuStrip control.

    System Indicates the use of a ToolStripSystemRenderer to Paint.
    Professional indicates the use of a ToolStripProfessionalRenderer to paint.

    Please try the code below to see the effects of setting the property:
            private void button1_Click(object sender, EventArgs e)
            {
                menuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
            }
            private void button2_Click(object sender, EventArgs e)
            {
                menuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            }

    We can also derive from ToolStripSystemRenderer or ToolStripProfessionalRenderer class to create our own renderer and set the menuStrip's renderer property to an instance of the derived class.
    Here is an example :
     How to: Create a Professionally Styled ToolStrip Control.

    Harry

    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.
    • Marked as answer by Harry Zhu Friday, January 15, 2010 3:04 AM
    Tuesday, January 12, 2010 9:32 AM
  • I gree with Harry, it is better to use these since they also might be
    more effecient for your use.

    The links provided by Harry are very useful as well.

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Tuesday, January 12, 2010 9:52 AM
  • Thank you very much this was very useful for me
    Friday, September 20, 2013 6:24 AM