How to add a MouseEnter event?
I've been very frustrated the last couple of hours trying to figure out how to add a mouse enter and mouse leave event to my program and it is killing me.
I've added a reference to System.Windows.Forms, imported the System.Windows.Forms namespace above my Form1 class, added:
Public
Event MouseEnterAs MouseEventHandlerPublicEvent MouseLeaveAs MouseEventHandler beneath the Form1 class, and added a private sub for both the MouseEnter and MouseLeave events I'm trying to do, but apparently I'm missing a step or two somewhere. Every example I have been able to find glosses over the details as if I'm supposed to have been born with the knowledge or something.
All I want to do is change the color of a button when my users hover their mouses over it. Can someone please help me?
Chris, I appreciate your help however, I'm still missing a step.
If I click on the button and then go to the event list, there is no event handler for MouseEnter or MouseLeave. That is my question! How do I get the event handler set up?
I'm thinking what is missing is that you haven't selected the button in the code window
try double clicking the button on your form, then in the code window you will see a combobox at the top that has your button name in it.
Directly over to the right you will see the word click in another combobox
drop the box down and then select the event
or what john said and then double click the event in the properties window
Try adding the code below and just change the name of
you button:
Public Class Form1
Private Sub Button1_MouseEnter(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.BackColor = Color.Blue
End Sub
Private Sub Button1_MouseLeave(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.BackColor = Color.IndianRed
End Sub
End Class
Yes, that's the code but why don't you have the events in your list?
If they really aren't there then you have problems
FYI
A moderator checked the answer, not the OP.
The OP may be back with more info / questions.