Gostaria de customizar minha trackBar em c#. Encontrei esse código em VB.net mas não sei como converte-lo.
Public Class myTrackBar
Inherits Control
Private Value As Integer
Private Pointer As New Bitmap(20, 40)
Private Rect As New Rectangle(10, 10, 20, 40)
Private Moving As Boolean
Private Offset As Integer
Public Sub New()
Size = New Size(210, 50)
DoubleBuffered = True
Using g As Graphics = Graphics.FromImage(Pointer)
g.Clear(Color.Transparent)
g.FillRectangle(Brushes.Blue, New Rectangle(0, 0, 10, 15))
g.FillPolygon(Brushes.Blue, New Point() {New Point(0, 15), New Point(5, 20), New Point(10, 15)})
End Using
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.FillRectangle(Brushes.Black, New Rectangle(0, 0, Width, Height))
Dim X As Integer = 15
For count As Integer = 1 To 10
e.Graphics.DrawLine(Pens.White, New Point(X, 35), New Point(X, 40))
X += 20
Next
Using P As New Pen(Brushes.Black, 1)
P.DashStyle = Drawing2D.DashStyle.Dot
e.Graphics.DrawRectangle(P, New Rectangle(1, 1, Width - 2, Height - 2))
End Using
e.Graphics.DrawImage(Pointer, Rect)
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
If Rect.Contains(e.Location) Then
Moving = True
Offset = e.Location.X - Rect.X
End If
End Sub
Protected Overrides Sub OnMouseup(ByVal e As System.Windows.Forms.MouseEventArgs)
Moving = False
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
If Moving Then
Rect.X = Math.Min(Math.Max(e.Location.X - Offset, 10), 190)
Invalidate()
End If
End Sub
End Class