单击时如何防止 MenuBar 下拉菜单中的背景色和前景色变化

How to prevent Backcolor and forecolor change in MenuBar Dropdowns On click

这是菜单栏下拉菜单 1

我们知道背景是

Color.FromARGB(61,61,61)

前景=Color.Purple

点击后看起来像:

我想阻止它改变背景颜色,当我在运行时将鼠标放在一个选项上时它也会改变背景颜色。我尝试添加一个 onclick sub,它在点击后保持背景颜色,但它仍然改变了。

根据this answer in c#, you can use a ToolStripProfessionalRenderer覆盖菜单的某些属性。

Public Class Form1
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        MenuStrip1.Renderer = New MyRenderer()
    End Sub
    Private Class MyRenderer
        Inherits ToolStripProfessionalRenderer
        Public Sub New()
            MyBase.New(New MyColors())
        End Sub
        Private Class MyColors
            Inherits ProfessionalColorTable
            Public Overrides ReadOnly Property MenuItemPressedGradientBegin As Color
                Get
                    Return Color.FromArgb(61, 61, 61)
                End Get
            End Property
            Public Overrides ReadOnly Property MenuItemPressedGradientEnd As Color
                Get
                    Return Color.FromArgb(61, 61, 61)
                End Get
            End Property
            Public Overrides ReadOnly Property MenuItemSelectedGradientBegin As Color
                Get
                    Return Color.FromArgb(61, 61, 61)
                End Get
            End Property
            Public Overrides ReadOnly Property MenuItemSelectedGradientEnd As Color
                Get
                    Return Color.FromArgb(61, 61, 61)
                End Get
            End Property
            Public Overrides ReadOnly Property MenuItemSelected As Color
                Get
                    Return Color.FromArgb(61, 61, 61)
                End Get
            End Property
        End Class
    End Class
End Class