简体   繁体   中英

How can I change the selected MenuStrip button color on click?

I have MenuStrip with 2 buttons. When I click one of them the color changes to white.

Not clicked

未点击

Clicked

已点击

How can I change the color of the clicked button when selected?

You need to supply your own Renderer:

public class RendererEx : ToolStripProfessionalRenderer {

  protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) {
    //base.OnRenderMenuItemBackground(e);
    e.Item.BackColor = Color.Black;
  }
}

Then apply it in the form's constructor:

menuStrip1.Renderer = new RendererEx();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM