1

我想检查我的鼠标是否在 datagridview 内部/外部。如果我的鼠标在外面,它应该运行我的计时器代码以在隐藏 datagridview 之前开始倒计时(在我的示例中为 2 秒)。如果它在里面,计时器应该将我的计数器重置为 0,以免隐藏我的数据网格视图..

下面是我的计时器的代码.. w/100 间隔

Private ctme As Integer = 0
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If DataGridView1.Visible = False Then ctme = 0 : Exit Sub
        If Not DataGridView1.Bounds.Contains(PointToClient(Cursor.Position)) Then
            ctme = ctme + 1
            If ctme >= 20 Then
                ctme = 0
                DataGridView1.Visible = False
            End If
        Else
            ctme = 0
        End If
    End Sub

我努力了

Datagridview1.ClientRectangle.Contains(PointtoClient(Cursor.Position))

代替

Datagridview1.Bounds.Contains(PointtoClient(Cursor.Position))

但它仍然不起作用..

希望你能帮我解决这个问题。。

4

2 回答 2

1

您可以使用MouseEnter(鼠标指针进入控件时发生)和MouseLeave(鼠标指针离开控件时发生)事件:

使用这个解决方案要简单得多:

Private Sub DataGridView1_MouseEnter(sender As Object, e As EventArgs) Handles DataGridView1.MouseEnter
    Timer1.Stop()
End Sub

Private Sub DataGridView1_MouseLeave(sender As Object, e As EventArgs) Handles DataGridView1.MouseLeave
    Timer1.Start()
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Timer1.Interval = 2000
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    DataGridView1.Visible = False
End Sub
于 2013-06-14T08:55:29.037 回答
-1

对于每个事件:

鼠标回车

Timer1.Stop()

鼠标离开

 Timer1.Start()

Form1_Load

Timer1.Interval = 2000

Timer1.Tick

DataGridView1.Visible = False
于 2013-08-28T03:49:56.083 回答