I have a form with a menu and a toolstrip at the top. The menuStrip has a nice looking gradient background, how can I get the same effect on the toolStrip control? I know about the RenderMode property but changing this doesn't have the desired result.
Asked
Active
Viewed 4,612 times
5
-
Dont think there is a property for that. There is `BackgroundImage` property if you wanted to make a gradiated image for that. – Colin Steel Sep 04 '13 at 12:28
-
How do you render your `MenuStrip` so that it has such a `gradient background`? I mean if you know how to render it, how may want to apply the same render on the `ToolStrip` so that the backgrounds of both are identical. – King King Sep 04 '13 at 13:19
-
The menuStrip is a plain menuStrip control with RenderMode set to "ManagerRenderMode", which is the default. I don't know how it's rendered. How would I apply the same renderer to the toolStrip? – PaulK Sep 04 '13 at 13:40
-
The MenuStrip and StatusStrip have a horizontal gradient while the ToolStrip has a vertical gradient. It is odd that Microsoft did it this way. – deegee Mar 03 '16 at 06:38
1 Answers
1
You can achieve this with a custom renderer.
public class CustomToolStripRenderer : ToolStripProfessionalRenderer
{
public CustomToolStripRenderer() { }
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
{
//you may want to change this based on the toolstrip's dock or layout style
LinearGradientMode mode = LinearGradientMode.Horizontal;
using (LinearGradientBrush b = new LinearGradientBrush(e.AffectedBounds, ColorTable.MenuStripGradientBegin, ColorTable.MenuStripGradientEnd, mode))
{
e.Graphics.FillRectangle(b, e.AffectedBounds);
}
}
}
Then set your toolstrip to use an instance of this renderer.
public Form1()
{
InitializeComponent();
CustomToolStripRenderer r = new CustomToolStripRenderer();
r.RoundedEdges = false;
toolStrip1.Renderer = r;
}

gannaway
- 1,872
- 12
- 14
-
Note that this doesn't work as intended when the ToolStrip contains items with drop-down menus. The drop-down menu backgrounds will also become gradient painted. – deegee Mar 03 '16 at 06:36