1

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

我的意思是:

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

在此处输入图像描述

但是我会在我的程序中更改它,对于我的面板,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

在此处输入图像描述

由于面板内的失真效果,我想更改滚动行数,如果我像 Windows SO 属性的图像一样使用“一个 scoll-page”或“10 次滚动”,那么我可以修复它!

4

3 回答 3

2

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

所以一个好的定义是:

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

来源:MSDN 上的 Control.MouseWheel 事件

于 2012-11-23T21:28:30.173 回答
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
于 2012-11-23T21:22:13.137 回答
1

SendMessage无论SystemInformation.MouseWheelScrollLines. _ 对于 Panel 不会发生 MouseWheel 事件。所以我在一个文本框上测试了这个:

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传递的值的符号。

于 2012-11-23T21:47:03.920 回答