You can use the TrackBar.Scroll event to limit the value:
Option Strict On
Option Infer On
' ...
Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
Dim tb = DirectCast(sender, TrackBar)
tb.Value = Math.Max(3, tb.Value)
lbTrackBar1Value.Text = tb.Value.ToString()
lbResult.Text = Calc(tb.Value).ToString()
End Sub
Which supposes that you have labels to display the trackbar value and the result of some function Calc
.
I used Dim tb = DirectCast(sender, TrackBar)
so it is easier to generalise the method to use for other trackbars.
Or you can use the TrackBar.ValueChanged Event, which has the feature that it will also be raised if you set the value programatically, as Visual Vincent was kind enough to point out.
If it matters that the handler is sometimes called more than once on a Scroll or ValueChanged event, then you can guard against running the code more than once like this:
Sub TrackBar1_ValueChanged(sender As Object, e As EventArgs) Handles TrackBar1.ValueChanged
Static inVC As Boolean = False
If inVC Then Return
Dim tb = DirectCast(sender, TrackBar)
inVC = True
tb.Value = Math.Max(3, tb.Value)
inVC = False
End Sub
The local static variable inVC
is initialised only once and retains its value between invocations.