Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have created a user control but it's mouse enter and mouse leave events are not get fired.
Please Help Me.


VB
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
Posted
Comments
Sandeep Mewara 7-May-13 10:38am    
Are the defined events tied up?
Sergey Alexandrovich Kryukov 7-May-13 10:51am    
You don't show the definitions of any events in your code sample. I can imaging that you have it in your auto-generated (by the designer) part of the class. But then, where is "Partial"? The problem is: instead of showing the code which could compile, you show who knows what. When you ask a question, you should better show some code sample, not your own code, but this code should be complete.
The part of the code which you show does not look reasonable.
—SA

1 solution

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.
 
Share this answer
 
Comments
PSAFOL 8-May-13 1:43am    
Thank You very much Dave Kreskowiak. I was solving it from 2 days, but you have solved it in 5 mins. Thank You very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900