Code:Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TrackBar1.Minimum = 0 TrackBar1.Maximum = 11 ' 0 to 11 will be 12 Ticks TrackBar1.SmallChange = 1 TrackBar1.LargeChange = 1 TrackBar1.Value = 0 End Sub Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint Dim dpw As Double = ((Panel1.Width - 1) / ((TrackBar1.Maximum - TrackBar1.Minimum) / TrackBar1.TickFrequency)) Dim tmp As Double = 0 For x As Integer = 0 To CInt(((TrackBar1.Maximum - TrackBar1.Minimum) / TrackBar1.TickFrequency)) Dim i As Integer = CInt(tmp) If i > Panel1.Width - 1 Then i = Panel1.Width - 1 If x <= TrackBar1.Value Then e.Graphics.DrawLine(Pens.Red, i, 0, i, e.ClipRectangle.Height) Else e.Graphics.DrawLine(Pens.Black, i, 0, i, e.ClipRectangle.Height) End If tmp += dpw Next End Sub Private Sub TrackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged Panel1.Refresh() 'Repaints the panel so the tick marks will change color as the value changes End Sub End Class




Reply With Quote