1

好吧,我正在尝试这样的事情:

    Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
    Dim scv As Int32 = TrackBar1.Value
    Dim uni As [String] = "ms"

    Select Case scv
        Case Is > 1000
            scv = scv \ 1000
            uni = "s"
            sender.SmallChange = 1000
        Case Is > 100
            sender.SmallChange = 50
        Case Is > 50
            sender.SmallChange = 50
        Case Is > 25
            sender.SmallChange = 25
        Case Is > 10
            sender.SmallChange = 15
    End Select

    Label4.Text = (scv & uni).ToString
End Sub

但是它的 onyl 与箭头键<>一起使用,如果我用鼠标移动或鼠标滚轮尝试它,它就不起作用。而且...只有当我从左到右时才有效...

我必须做什么?:(

4

2 回答 2

2

试试这样的东西...

Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
    Dim bar As TrackBar = DirectCast(sender, TrackBar)

    Select Case bar.Value
        Case Is >= 1000
            bar.SmallChange = 1000
        Case Is > 100
            bar.SmallChange = 50
        Case Is > 50
            bar.SmallChange = 50
        Case Is > 25
            bar.SmallChange = 25
        Case Is > 10
            bar.SmallChange = 15
    End Select

    Dim discrete As Integer = TrackBar1.Value \ TrackBar1.SmallChange
    Dim Value As Integer = discrete * bar.SmallChange
    bar.Value = Math.Min(Math.Max(bar.Minimum, Value), bar.Maximum)

    Label4.Text = IIf(bar.Value >= 1000, bar.Value \ 1000, bar.Value) & IIf(bar.Value >= 1000, "s", "ms")
End Sub
于 2013-07-05T02:21:13.180 回答
1

永远不要使用 TrackBar .. 但我认为它应该像这样 ..

Dim Trb as TrackBar = CType(sender,TrackBar)

Trb.SmallChange = 1000 

'and so on ..
于 2013-07-04T16:14:39.700 回答