VB更改颜色边框menustrip

时间:2016-11-20 23:13:25

标签: vb.net menustrip

我在我的应用程序中添加了menustrip,我希望在menustrip上更改边框颜色。我找到了一些代码,但你可以在图片上看到我有一个边框。

图片:

enter image description here

我的代码:

Public Class ColorTable
    Inherits ProfessionalColorTable

    Dim Color1 = Color.FromArgb(30, 38, 44)
    Dim Color2 = Color.FromArgb(75, 81, 88)

    Public Overrides ReadOnly Property MenuBorder() As Color
        Get
            Return Color1
        End Get
    End Property

    Public Overrides ReadOnly Property MenuItemSelectedGradientBegin() As Color
        Get
            Return Color2
        End Get
    End Property

    Public Overrides ReadOnly Property MenuItemSelectedGradientEnd() As Color
        Get
            Return Color2
        End Get
    End Property

    Public Overrides ReadOnly Property MenuItemSelected() As Color
        Get
            Return Color2
        End Get
    End Property

    Public Overrides ReadOnly Property MenuItemBorder() As Color
        Get
            Return Color1
        End Get
    End Property

    Public Overrides ReadOnly Property MenuItemPressedGradientBegin() As Color
        Get
            Return Color2
        End Get
    End Property

    Public Overrides ReadOnly Property MenuItemPressedGradientEnd() As Color
        Get
            Return Color2
        End Get
    End Property

End Class

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Menus.Renderer = New ToolStripProfessionalRenderer(New ColorTable())
End Sub

2 个答案:

答案 0 :(得分:0)

您还想要覆盖以下属性:

Public Overrides ReadOnly Property SeparatorDark() As Color
    Get
        Return Color1
    End Get
End Property

Public Overrides ReadOnly Property ToolStripDropDownBackground() As Color
    Get
        Return Color1
    End Get
End Property

这将涵盖背景和您添加的任何分隔符。

答案 1 :(得分:0)

我已添加

        Public Overrides ReadOnly Property ImageMarginGradientBegin() As System.Drawing.Color
        Get
            Return Color1
        End Get
    End Property
    Public Overrides ReadOnly Property ImageMarginGradientEnd() As System.Drawing.Color
        Get
            Return Color1
        End Get
    End Property
    Public Overrides ReadOnly Property ImageMarginGradientMiddle() As System.Drawing.Color
        Get
            Return Color1
        End Get
    End Property

现在一切正常:)