更改鼠标滚轮线?

时间:2012-11-23 21:02:28

标签: vb.net scroll scrollbar mouseevent mousewheel

我有一个带自动滚动的面板,我需要更改鼠标滚动行号

我的意思是:

(西班牙语中的鼠标属性,抱歉)

enter image description here

但我会在我的程序中更改它,对于我的面板,obvius,而不是在SO!

PS:例如Winamp媒体播放器可以选择。

我无法在任何地方找到信息,请帮助。

  

更新

我的滚动条是一个带有“AutoScroll”属性的面板

我的活动是这样的:

    Private Sub Panel1_MouseScroll(sender As Object, e As MouseEventArgs) Handles Panel1.MouseWheel

    Panel1.Invalidate()

    End Sub

这是我的小组的内容:

  ' Checkbox drawing
Public Sub updatecheckboxes()
    ' delete the old checkboxes
    Panel1.Controls.Clear()
    ' create the new checkboxes
    Dim filesystem = CreateObject("Scripting.FileSystemObject")
    Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
    Dim i As Int32 = 0
    Dim pos As Int32 = 10
    For Each folder In ThisDir.Subfolders
        Array.Resize(mcheck, i + 1)
        mcheck(i) = New CheckBox
        With mcheck(i)
            .AutoSize = True
            .Location = New Point(10, pos)
            .Name = "CheckBox" & i + 1
            .Text = folder.Name
        End With
        Me.Panel1.Controls.Add(mcheck(i))
        AddHandler mcheck(i).CheckedChanged, AddressOf LlamadaCheckBox
        i += 1
        pos += 20
    Next

End Sub

enter image description here

我想更改滚动线的数量,因为面板内的扭曲效果,如果我使用“一个scoll-page”或“10个滚动时间”,如Windows SO属性的imagen,那么我可以解决它!

3 个答案:

答案 0 :(得分:2)

MouseEventArgs对象具有属性Delta,用于确定鼠标滚轮的滚动量。此外,还有SystemInformation.MouseWheelScrollLines。有一个名为WHEEL_DELTA = 120的当前常量,它反映了每个鼠标滚轮刻度添加的增量。

所以一个好的定义是:

Dim numberOfTextLinesToMove As Integer = CInt(e.Delta * SystemInformation.MouseWheelScrollLines / 120)

来源:Control.MouseWheel Event on MSDN

答案 1 :(得分:1)

您可以查看MouseWheel事件的MSDN示例。他们建议这样的事情你可以通过用你要滚动的行数替换SystemInformation.MouseWheelScrollLines来改变更改的数量。

来自链接:

Private Sub panel1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseWheel
        ' Update the drawing based upon the mouse wheel scrolling. 
    Dim numberOfTextLinesToMove As Integer = CInt(e.Delta * SystemInformation.MouseWheelScrollLines / 120)
    Dim numberOfPixelsToMove As Integer = numberOfTextLinesToMove * fontSize

    If numberOfPixelsToMove <> 0 The
        Dim translateMatrix As New System.Drawing.Drawing2D.Matrix()
        translateMatrix.Translate(0, numberOfPixelsToMove)
        mousePath.Transform(translateMatrix)
    End If
    panel1.Invalidate()
End Sub

另一个例子:

我转向AutoScroll因为它似乎想要至少给你一个最小的系统滚动线。我不得不进行一些检查,以防止不断滚动传递范围。玩它,看看它是否适合你。

Private Sub panel1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseWheel
    Dim numberOfTextLinesToMove As Integer = CInt(e.Delta * 20 / 120)
    Dim numberOfPixelsToMove As Integer = numberOfTextLinesToMove * mcheck(0).Font.Size

    If numberOfPixelsToMove <> 0 Then
        If (numberOfPixelsToMove > 0) Then
            If (mcheck(0).Top >= 0) Then Exit Sub
        Else
            If (mcheck(mcheck.Length - 1).Top) <= Panel1.Height Then Exit Sub
        End If

        TranslateCheckboxes(numberOfPixelsToMove)
    Else
        Exit Sub
    End If
    Panel1.Invalidate()
End Sub

Private Sub TranslateCheckboxes(pixels As Integer)
    For x = 0 To mcheck.Length - 1
        mcheck(x).Top += pixels
    Next
End Sub

答案 2 :(得分:1)

无论SendMessage中的内容是什么,您都可以使用SystemInformation.MouseWheelScrollLines滚动所需的任意行数。 MouseWheel event does not occur for a Panel。所以我在TextBox上测试了这个:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
               (ByVal handle As IntPtr, ByVal wMsg As Integer,
                ByVal wParam As Integer, ByVal lParam As Integer) As Integer

向上滚动一行:

SendMessage(TextBox1.Handle, &HB6, 0, -1)

向下滚动一行:

SendMessage(TextBox1.Handle, &HB6, 0, 1)

最后一个参数是多行,符号表示方向。消极 - 向上,正向 - 向下。

您应该能够覆盖/禁止鼠标滚轮处理并插入这两个语句,具体取决于传递的delta值的符号。