在vb.net中鼠标悬停时更改menustrip菜单项颜色 [英] Change the menustrip menu item color on mouse hover in vb.net

查看:566
本文介绍了在vb.net中鼠标悬停时更改menustrip菜单项颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何在vb.net中鼠标悬停时更改menustrip菜单项颜色。



谢谢

Sivasankaran G

Hi

How to Change the menustrip menu item color on mouse hover in vb.net.

Thanks
Sivasankaran G

推荐答案

同意SA,如果它是web应用程序,那么就使用JQuery。



谢谢,

Ambesha
Agree with SA, if it is web app then use JQuery for same .

Thanks,
Ambesha


如果您正在谈论桌面应用程序,那么更改RenderMode到系统。它将起作用。
If you are talking about Desktop Application then change RenderMode to System. It will work.


要更改菜单条颜色,只需打开vb.net,创建一个新的Windows窗体应用程序,然后在form1上添加菜单条,并输入以下代码:

'由开发人员撰写:Amar Tufo

To change the menu strip color just open vb.net, create a new windows form application, and on form1 add menu strip, and type in the follow code:
'written by developer: Amar Tufo
Public Class Form1
    Inherits Form
    Public Sub New()
        Try
            ' initialize added component on form1, which is menu strip;
            'note: if you have added any second component alongside menu
            'strip, such as context menu strip just add additional code 
            'line under InitializeComponent(), and it will work;
            InitializeComponent()
            MenuStrip1.Renderer = New MyRenderer()
        Catch ex As Exception

        End Try
    End Sub
    Public Class MyRenderer
        Inherits ToolStripProfessionalRenderer
        Protected Overloads Overrides Sub OnRenderMenuItemBackground(ByVal e As ToolStripItemRenderEventArgs)
            Try
                Dim rc As New Rectangle(Point.Empty, e.Item.Size)
                Dim c As Color = IIf(e.Item.Selected, Color.DodgerBlue, Color.Red)
                Using brush As New SolidBrush(c)
                    e.Graphics.FillRectangle(brush, rc)
                End Using
            Catch ex As Exception

            End Try

        End Sub
    End Class





这部分代码必须在form1上插入你之前在表单上添加的菜单条,但必须添加异常尝试处理顺序t o跳过应用程序中的任何错误或错误。



this part of code must be inserted on form1 alongside menu strip you previously added on form, but it must be added with exception try handling in order to skip any bug or error in your application.


这篇关于在vb.net中鼠标悬停时更改menustrip菜单项颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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