0
votes

Here's the image and the code.....but, it is not working for me. Experts, please tell where's the error???

the image is here: https://drive.google.com/open?id=1rUBq68ULDkTiFFv2uEiV_oQIh3wQIfhd

Private Sub PanelHome_MouseEnter(sender As Object, e As EventArgs) Handles PanelHome.MouseEnter
    PanelHome.BackColor = Color.FromArgb(100, 25, 181, 254)
End Sub

Private Sub PanelHome_MouseLeave(sender As Object, e As EventArgs) Handles PanelHome.MouseLeave
    PanelHome.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub

Private Sub PanelTuner_MouseEnter(sender As Object, e As EventArgs) Handles PanelTuner.MouseEnter
    PanelTuner.BackColor = Color.FromArgb(50, 25, 181, 254)
End Sub

Private Sub PanelTuner_MouseLeave(sender As Object, e As EventArgs) Handles PanelTuner.MouseLeave
    PanelTuner.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub

Private Sub PanelContents_MouseEnter(sender As Object, e As EventArgs) Handles PanelContents.MouseEnter
    PanelContents.BackColor = Color.FromArgb(50, 25, 181, 254)
End Sub

Private Sub PanelContents_MouseLeave(sender As Object, e As EventArgs) Handles PanelContents.MouseLeave
    PanelContents.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub

Private Sub PanelAboutUs_MouseEnter(sender As Object, e As EventArgs) Handles PanelAboutUs.MouseEnter
    PanelAboutUs.BackColor = Color.FromArgb(50, 25, 181, 254)
End Sub

Private Sub PanelAboutUs_MouseLeave(sender As Object, e As EventArgs) Handles PanelAboutUs.MouseLeave
    PanelAboutUs.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub

Private Sub PanelWriteToUs_MouseEnter(sender As Object, e As EventArgs) Handles PanelWriteToUs.MouseEnter
    PanelWriteToUs.BackColor = Color.FromArgb(50, 25, 181, 254)
End Sub

Private Sub PanelWriteToUs_MouseLeave(sender As Object, e As EventArgs) Handles PanelWriteToUs.MouseLeave
    PanelWriteToUs.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub

Edit1: The panel's dock is set to fill....

2
I think it should be mouseHover not mouseEnter - kiLLua
@kiLLua : No, MouseHover waits for the mouse to stay still over the control for 400 milliseconds before being raised. MouseEnter is the right way to go. See the documentation for MouseEnter and MouseHover. - Visual Vincent
you are right @Visual Vincent..... - tejasgupta
What do mean with not working? Is the event never raised? Check whether a container is Enable=False, by chance. - Jimi
i checked....they are enabled.......but, one thing i forgot to mention is that they have dock set to fill.... - tejasgupta

2 Answers

0
votes

Even if the panel's dock is Fill, your code works for me... I think you should try to isolate the problem. If I create a form with 2 panels, one Docked to TOP, and the other Docked to FILL, your code works for me, using the events MouseEnter and MouseLeave... Your problem is not the dock property, and is not the events used.

If you still cannot find the problem, you could start with a new Form and adding the code step by step until you find the step that make your program to stop working.

0
votes

Mouse events are only raised if the mouse touches the panel itself. If you have other controls inside the panel then when the mouse is over them their mouse events will be raised instead.

In your image you appear to have a PictureBox that covers each panel, meaning you would have to handle its MouseEnter and MouseLeave events as well for this to work:

Private Sub PanelHome_MouseEnter(sender As Object, e As EventArgs) Handles PanelHome.MouseEnter, PictureBoxHome.MouseEnter
    PanelHome.BackColor = Color.FromArgb(100, 25, 181, 254)
End Sub

Private Sub PanelHome_MouseLeave(sender As Object, e As EventArgs) Handles PanelHome.MouseLeave, PictureBoxHome.MouseLeave
    'Check if the mouse is still inside the control's bounds.
    If Not PanelHome.DisplayRectangle.Contains(Cursor.Position) Then
        PanelHome.BackColor = Color.FromArgb(255, 25, 181, 254)
    End If
End Sub

(you need to do the same for the rest of your code as well)

However if you don't need to change these panels in any other way than the background color then it would be better to remove the panels and only keep the picture boxes.