如何在鼠标滚动时或在列表框中滚动条的顶部停止计时器 [英] How to stop a timer when mouse is scrolling or on top of scrollbar in listbox

查看:66
本文介绍了如何在鼠标滚动时或在列表框中滚动条的顶部停止计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在鼠标光标滚动列表框时检测和关闭计时器的方法.尽管创建了这样的新类,但有一种简单的方法吗?链接

I'm looking for a way to detect and switch off a timer when the mouse cursor is scrolling a listbox. There is an easy way despite to create a new class like this one?link

是否可以检查列表框 1 滚动条的矩形位置并说:如果鼠标在此范围内,则 timer1.stop?

Would be possible to check rectangle location of listbox 1 scroll bar and say: if mouse is in this range then timer1.stop?

编辑 1:为了创建我正在使用的矩形

In order to create a rectangle I'm using

 If e.X >= 364 AndAlso e.X <= 446 AndAlso e.Y >= 86 AndAlso e.Y <= 144 Then
        MessageBox.Show("Clicked within the rectangle")
    Else
        MessageBox.Show("Clicked outside the rectangle")
    End If

449-359 是矩形的左上角位置而矩形大小为 x30 y156问题是我不知道在哪个事件中让它运行!列表框单击事件无法将滚动条识别为列表框内部";Form_mouse 单击事件无法将列表框滚动条识别为表单中的单击.有一个事件,尽管您处于控制状态,但它会让您使用此解决方法吗?谢谢

449-359 are the Top left corner location of the rectangle while the rectangle size is x30 y156 The problem is I don't know in which event let it run! Listbox click event doesn't recognize scrollbar as "inside of listbox" Form_mouse click event doesn't recognize listbox scroll bar as a click in the form. There is an event that despite the control you are on, it will let you play with this workaround? Thanks

推荐答案

这是我发布的内容 on MSDN 使用 这个 C# 代码.下面没有提供重新启动计时器的代码.

Here is what I posted on MSDN using this C# code. There is no code presented below that will restart the Timer.

Public Class BetterListBox
    Inherits ListBox

    ' Event declaration
    Public Delegate Sub BetterListBoxScrollDelegate(ByVal Sender As Object, ByVal e As BetterListBoxScrollArgs)
    Public Event Scroll As BetterListBoxScrollDelegate
    ' WM_VSCROLL message constants
    Private Const WM_VSCROLL As Integer = &H115
    Private Const SB_THUMBTRACK As Integer = 5
    Private Const SB_ENDSCROLL As Integer = 8

    Protected Overrides Sub WndProc(ByRef m As Message)
        ' Trap the WM_VSCROLL message to generate the Scroll event
        MyBase.WndProc(m)

        If m.Msg = WM_VSCROLL Then
            Dim nfy As Integer = m.WParam.ToInt32() And &HFFFF
            If (nfy = SB_THUMBTRACK OrElse nfy = SB_ENDSCROLL) Then
                RaiseEvent Scroll(Me, New BetterListBoxScrollArgs(Me.TopIndex, nfy = SB_THUMBTRACK))
            End If
        End If
    End Sub
    Public Class BetterListBoxScrollArgs
        ' Scroll event argument
        Private mTop As Integer
        Private mTracking As Boolean
        Public Sub New(ByVal top As Integer, ByVal tracking As Boolean)
            mTop = top
            mTracking = tracking
        End Sub
        Public ReadOnly Property Top() As Integer
            Get
                Return mTop
            End Get
        End Property
        Public ReadOnly Property Tracking() As Boolean
            Get
                Return mTracking
            End Get
        End Property
    End Class
End Class

然后在您的表单中订阅 Scroll 事件.需要在您的项目中使用上面的 ListBox,启用一个 Timer 和一个 Label.

Then in your form subscribe to the Scroll event. Requires the ListBox above in your project, one Timer enabled and a Label.

Private Sub BetterListBox1_Scroll(Sender As Object, e As BetterListBox.BetterListBoxScrollArgs) _
    Handles BetterListBox1.Scroll

    Timer1.Enabled = False

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Label1.Text = Now.ToString()
End Sub

这篇关于如何在鼠标滚动时或在列表框中滚动条的顶部停止计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆