ToolStrip的VS MenuStrip中 - 我可以让他们呈现相同的?ToolStrip、VS、MenuStrip

2023-09-06 07:51:59 作者:抛开世俗 ,

我需要直接在我的应用程序中的MenuStrip下方显示一个工具条,但设置RenderMode =专业为各不给相同的结果。它们都显示出背景梯度,但不是同一个。

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.

有没有一些方法来使用的MenuStrip渲染的工具条,或者相反? 或者有人可以告知如何最好地实现梯度我自己,我可以在一个子类渲染器执行?

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?

后加入: 非常感谢 nobugz 低于他的答案。有用的材料也是在这个答案。 这里有一个更多的问题 - 如果我基地我的自定义渲染的ToolStripProfessionalRenderer并覆盖OnRenderToolstripBackground,我仍然可以弯曲的右手角落我的ToolStrip却没有关于我的MenuStrip。是否有某种内在的逻辑,它提供了不同的区域填充的背景渲染?我已经关闭了(有一个什么都不做功能覆盖)边境渲染器。

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.

推荐答案

我看不到它,但可以想像这是一个问题。覆盖渲染所以它使用相同的背景渲染为菜单项和工具条项目:

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