1

如何检查我的mouse cursor enters any component in a panel.

我盯着写这段代码来检查鼠标何时进入我的任何复选框panel然后我意识到我不知道如何实际检查鼠标是否进入面板中的组件。

 Private Sub GenCheck()
    For Each CheckBox In datapanel1.Controls


    Next
End Sub

我该怎么做呢?

编辑

我有一个想法,但我不太确定

我可以说

 Private Sub GenCheck()



       Dim cb As CheckBox
    For Each cb In datapanel1.Controls
        AddHandler cb.MouseEnter, AddressOf cb_MouseEnter
        AddHandler cb.MouseLeave, AddressOf cb_MouseLeave
    Next



End Sub
Private Sub cb_MouseEnter(sender As Object, e As EventArgs)

End Sub

Private Sub cb_MouseLeave(sender As Object, e As EventArgs)

End Sub
4

2 回答 2

1

您可以使用MouseHover来确定光标何时悬停在checkbox这样的上方。

Private Sub CheckBox1_MouseHover(sender As Object, e As System.EventArgs) Handles CheckBox1.MouseHover        
    MsgBox("Mouse over!")
End Sub`

编辑:

我在一个带有两个复选框的表单上放置了一个面板来模仿您的要求,这就是您要寻找的内容:

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    For Each pnlCheckBox As CheckBox In Panel1.Controls
        AddHandler pnlCheckBox.MouseHover, AddressOf Me.CheckBoxMouseOver
    Next
End Sub

Private Sub CheckBoxMouseOver()
    MsgBox("Mouse over!")
End Sub
于 2013-07-09T17:53:10.783 回答
1

*完美的方式来完成这个*

 Dim con As Control

    For Each con In datapanel1.Controls
        AddHandler con.MouseEnter, AddressOf con_MouseEnter
        AddHandler con.MouseLeave, AddressOf con_MouseLeave
    Next
End Sub
Private Sub con_MouseEnter(sender As Object, e As EventArgs)

    'DO SOMETHING'
End Sub

Private Sub con_MouseLeave(sender As Object, e As EventArgs)
   'DO SOMETHING'
End Sub
于 2013-07-09T19:23:40.897 回答