问题
I need to display a toolstrip directly beneath a menustrip in my application, but setting RenderMode = Professional for each does not give identical results. They both show a background gradient, but not the same one.
Is there some way to use menustrip rendering for the toolstrip, or vice versa? Or can someone advise how best to implement a gradient myself, that I can perform in a sub-classed renderer?
ADDED LATER:
Many thanks to nobugz for his answer below. Helpful material is also in this answer.
There's just one more issue -- if I base my custom renderer on the ToolStripProfessionalRenderer and override OnRenderToolstripBackground, I still get curved right-hand corners on my ToolStrip but not on my MenuStrip. Is there some internal logic that provides a different Region for filling by the background renderer? I've turned off (overridden with a do-nothing function) the border renderer.
回答1:
I don't see it but can imagine it's a problem. Override the renderer so it uses the same background renderer for both menu items and toolstrip items:
Public Class Form1
Public Sub New()
InitializeComponent()
MenuStrip1.Renderer = New MyRenderer()
End Sub
Private Class MyRenderer
Inherits ToolStripProfessionalRenderer
Protected Overrides Sub OnRenderItemBackground(ByVal e As ToolStripItemRenderEventArgs)
MyBase.OnRenderMenuItemBackground(e)
End Sub
End Class
End Class
回答2:
You can dock two panel using DockStyle.Top
, on top of each other, and then add a MenuStrip
to each of them. I did the same on my app, I needed a few MenuStrips
on rather exotical places. It can give a good result if you use a contiguos background for them.
来源:https://stackoverflow.com/questions/1756583/toolstrip-vs-menustrip-can-i-make-their-rendering-identical