Search code examples
vb.netbuttonlistboxmouseleavemousehover

Avoid mouseHover and mouseLeave for button placed inside the same Listbox


Im trying to show Buttons placed over a Listbox (similar to acrobat reader toolbox): when the user move the mouse inside the ListBox the buttons appears, and they must hide when the user leave the ListBox area. The problem is: when i move the mouse over the listbox the button appears but when I try to click on it, the program detect this movement as ListBox_MouseLeave and hides the button!... Thats logic (the mouse now is over the button)but...

Private Sub ListBox3_MouseHover(sender As Object, e As MouseEventArgs) Handles ListBox3.MouseHover
    Button6.Visible = True
End Sub

Private Sub ListBox3_MouseLeave(sender As Object, e As EventArgs) Handles ListBox3.MouseLeave
    Button6.Visible = False
End Sub

How can I avoid the mouse_leave instruction and let the button visible to use?


Solution

  • Move your hide code to the form mouse hoover.

    Private Sub Form4_MouseHover(sender As Object, e As EventArgs) Handles Me.MouseHover
            Button1.Visible = False
        End Sub
    
        Private Sub ListBox1_MouseEnter(sender As Object, e As EventArgs) Handles ListBox1.MouseEnter
            Button1.Visible = True
        End Sub