Change BackColor of ToolStripItem on Mouse Over [d

2019-08-10 07:32发布

This question already has an answer here:

So I have a MenuStrip in C# which I am trying to do a darkish theme for, but when I press the button for the dropdown menu well....

enter image description here

Is there a way to make it go from white to another color? I can't seem to figure out a way to do it. This is probably my first time even customizing context menus.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-08-10 08:11

You could use MouseHover and MouseLeave event. It's easy. Just do the following steps:

  1. We have a form with these items: http://s3.picofile.com/file/8188577184/Capture.JPG

  2. Choose that dark backcolor for ToolStripMenuItem. I choosed black color for fileToolStripMenuItem in my example.

  3. Use this for MouseHover event:

    private void fileToolStripMenuItem_MouseHover(object sender, EventArgs e)
    {
            fileToolStripMenuItem.BackColor = Color.White;
            fileToolStripMenuItem.ForeColor =Color.Black;
    }
    
  4. Use this for MouseLeave event:

    private void fileToolStripMenuItem_MouseLeave(object sender, EventArgs e)
    {
            fileToolStripMenuItem.BackColor = Color.Black;
            fileToolStripMenuItem.ForeColor = Color.White;
    }
    
查看更多
登录 后发表回答