Search code examples
vb.netmenustrip

VB change color border menustrip


I add a menustrip in my application and I want change border color on the menustrip. I have found some code but you can see on the picture I have a border again.

Picture :

enter image description here

My code :

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

Solution

  • You are going to want to also override the following properties:

    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
    

    This will cover the background and any separators you happen to add.