1,105,534 Community Members

Change HighLight Color MenuItem?

Member Avatar
Aangiix3
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, I have been trying to change the highlight color when the mouse gets on it of the stripmenu...how do I do that? Thanks in advance.

Member Avatar
Oxiegen
Master Poster
765 posts since Jun 2006
Reputation Points: 88 [?]
Q&As Helped to Solve: 149 [?]
Skill Endorsements: 7 [?]
Featured
 
1
 

You can use the MouseMove event and check if the mouse pointer is within the Bounds of the stripmenu item.
If that's the case, simply change the BackgroundColor.

Private Sub menuitem1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
        If menuitem1.Bounds.Contains(e.Location) Then
            menuitem1.BackColor = Color.Beige
        Else
            menuitem1.BackColor = Color.White
        End If
    End Sub
Member Avatar
Aangiix3
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This does not solve my problem. The Highlight color still is blue. I don't know where I can choose the highlight color, there isn't any option, and I didn't found any solution on the Internet. Please help me.

Member Avatar
Oxiegen
Master Poster
765 posts since Jun 2006
Reputation Points: 88 [?]
Q&As Helped to Solve: 149 [?]
Skill Endorsements: 7 [?]
Featured
 
0
 

Alright. Try this instead.
In the forms load event, add this line: <name of menustrip>.Renderer = New MyRenderer Then, within the forms own class add a private class called MyRenderer which inherits ToolStripProfessionalRenderer.

Private Class MyRenderer : Inherits ToolStripProfessionalRenderer
        Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
            If e.Item.Selected Then
                Dim rc As New Rectangle(Point.Empty, e.Item.Size)

                'Set the highlight color
                e.Graphics.FillRectangle(Brushes.Beige, rc)
                e.Graphics.DrawRectangle(Pens.Beige, 1, 0, rc.Width - 2, rc.Height - 1)
            Else
                Dim rc As New Rectangle(Point.Empty, e.Item.Size)

                'Set the default color
                e.Graphics.FillRectangle(Brushes.Gray, rc)
                e.Graphics.DrawRectangle(Pens.Gray, 1, 0, rc.Width - 2, rc.Height - 1)
            End If
        End Sub
    End Class
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: