对于menustripitem鼠标悬停事件 [英] mouseover event for menustripitem

查看:572
本文介绍了对于menustripitem鼠标悬停事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在menustrip.I一些的MenuStrip项目要设置的MenuStrip项目的颜色当鼠标在menustripitem.Is有可能有一个menustripitem鼠标悬停事件。

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.

在此先感谢。

推荐答案

您需要创建自己的渲染器,并分配MenuStrip.Renderer财产。下面是一个例子,这将需要一些工作,更好看:

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);
        }
    }
}

这篇关于对于menustripitem鼠标悬停事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆