mouseover event for menustripitem

可紊 提交于 2019-12-08 13:02:28

问题


I have some menustrip Items in my menustrip.I want to set the color of the menustrip item when the mouse is on the menustripitem.Is it possible to have mouseover event for a menustripitem.

Thanks in Advance.


回答1:


You need to create your own renderer and assign the MenuStrip.Renderer property. Here's an example, it is going to need some work to look better:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        menuStrip1.Renderer = new MyRenderer();
    }
    private class MyRenderer : ToolStripProfessionalRenderer {
        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) {
            if (e.Item.Selected) {
                e.Graphics.FillRectangle(Brushes.Bisque, e.Item.Bounds);
            }
            else base.OnRenderMenuItemBackground(e);
        }
    }
}



回答2:


You should use MouseEnter event of menustripitem.



来源:https://stackoverflow.com/questions/7415202/mouseover-event-for-menustripitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!