用户控件的事件不会被触发 [英] User Control's Event are not get fired

查看:84
本文介绍了用户控件的事件不会被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个用户控件,但它的鼠标输入和鼠标离开事件都没有被触发。

请帮帮我。




I have created a user control but it''s mouse enter and mouse leave events are not get fired.
Please Help Me.


Public Class ButtonTemplet
    Inherits UserControl

    Private mButtonText As String
    Public Property ButtonText As String
        Set(value As String)
            lblTitle.Text = value
        End Set
        Get
            Return lblTitle.Text
        End Get
    End Property

    Private Sub ButtonTemplet_MouseEnter(sender As System.Object, e As System.EventArgs) Handles MyBase.MouseEnter
        Me.BackgroundImage = Global.WindowsApplicationDemo.My.Resources.Resources.Clients_grey_button_Templet
        Me.lblTitle.ForeColor = Color.White
    End Sub

    Private Sub ButtonTemplet_MouseLeave(sender As System.Object, e As System.EventArgs) Handles MyBase.MouseLeave
        Me.BackgroundImage = Global.WindowsApplicationDemo.My.Resources.Resources.Orders_white_button_Templet
        Me.lblTitle.ForeColor = Color.Gray
    End Sub

    Protected Overrides Sub OnMouseEnter(e As System.EventArgs)
        MyBase.OnMouseEnter(e)
        Me.BackgroundImage = Global.WindowsApplicationDemo.My.Resources.Resources.Clients_grey_button_Templet
        Me.lblTitle.ForeColor = Color.White
    End Sub

    Protected Overrides Sub OnMouseLeave(e As System.EventArgs)
        MyBase.OnMouseLeave(e)
        Me.BackgroundImage = Global.WindowsApplicationDemo.My.Resources.Resources.Orders_white_button_Templet
        Me.lblTitle.ForeColor = Color.Gray
    End Sub
End Class

推荐答案

如果我没记错的话,那些事件只会在鼠标位于UserControl表面的一部分上时触发对它有一个组成控制。因此,例如,如果您有一个Dock.Filled到整个UserControl表面的按钮,那些事件将永远不会触发,因为鼠标无法看到UserControl表面,只有按钮位于其上面。
If I remember correctly, those events will only fire if the mouse is over a portion of the UserControl surface that does NOT have a constituent control on it. So, for example, if you have a button that is Dock.Filled to the entire UserControl surface, those event will never fire because the mouse cannot see the UserControl surface, only the button sitting on top of it.


这篇关于用户控件的事件不会被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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