1

Well I'm trying something like that:

    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

But its onyl works with the arrow keys < and >, if I try it with the mouse move or the mouse scroll wheel, doesn't work. And... Only work if I go from Left to Right...

What I have to do? :(

Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
Seazoux
  • 621
  • 1
  • 5
  • 28
  • I think I understand. When using the mouse you want it to "jump" in discrete chunks based on the SmallChange value just like when you use the arrow keys? To do that I think you'd have to compute what the new Value should be a change it in real-time. – Idle_Mind Jul 04 '13 at 18:35
  • Yes, you have understand all... If you post the code I will vote up you ;) – Seazoux Jul 04 '13 at 18:37

2 Answers2

2

Try something like this out...

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
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • You code is almost good, only I don't know why the marker gets caught in 9 seconds... :( – Seazoux Jul 05 '13 at 10:16
  • Not sure...I setup mine to go from 0 (zero) to 10,000 and it seemed to go fine. What are the parameters for yours? Can you post screenshots and describe in more detail what happens? – Idle_Mind Jul 05 '13 at 14:56
  • http://gyazo.com/057ced626df0c928f9f76e81cb39209c http://gyazo.com/8118a73436f60c55eecf6cb94e02144f This is where the marker gets caught: http://gyazo.com/142df16309c0ff61f3ca5a7af1cc994e "Velocidad" in English is speed and "Velocidad personalizada" is "Custom speed". ;) – Seazoux Jul 05 '13 at 15:03
  • Does it go past the 9?...or does it just stop there completely? – Idle_Mind Jul 05 '13 at 15:13
  • It just stop there completely. – Seazoux Jul 05 '13 at 15:16
  • In the last picture it looks like the max is much greater than 10,000. What is it set at in that last picture? – Idle_Mind Jul 05 '13 at 15:32
  • Got it...see the updated code above. The three lines starting at `Dim discrete` are different. – Idle_Mind Jul 05 '13 at 15:57
  • Wow! It's perfect, only one more thing :P Can you make that the Marker move with the Tick Lines? (PD: I was busy and I don't see your msg before. =P) – Seazoux Jul 05 '13 at 21:51
1

Never use TrackBar .. but I think it should like this ..

Dim Trb as TrackBar = CType(sender,TrackBar)

Trb.SmallChange = 1000 

'and so on ..
matzone
  • 5,703
  • 3
  • 17
  • 20