Imports System.Drawing.Drawing2D Imports System.Drawing.Text Public Class CustomVScrollBar Inherits Control Dim Thumb As Rectangle Dim _ColorScheme As ColorScheme Dim _thumby As Integer Dim _vis As Double = 1 Dim _thumbsize As Integer = 20 Dim _val As Double Dim Pressed As Boolean = False Public Event Scroll() Property VisibleRatio As Double Get Return _vis End Get Set(ByVal value As Double) _vis = value _thumbsize = CInt(Height * _vis) Invalidate() End Set End Property Property Value As Double Get Return _val End Get Set(ByVal value As Double) _val = value Invalidate() RaiseEvent Scroll() End Set End Property Public Property ColorScheme As ColorScheme Get Return _ColorScheme End Get Set(value As ColorScheme) _ColorScheme = value Invalidate() End Set End Property Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs) If e.Button = MouseButtons.Left Then If Thumb.Contains(e.Location) Then Pressed = True Else If e.Y < Thumb.Y Then _thumby = CInt(_val - 10) Else _thumby = CInt(_val + 10) _val = Math.Min(Math.Max(_thumby, 0), 100) Invalidate() RaiseEvent Scroll() End If End If End Sub Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs) Pressed = False End Sub Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs) If Pressed Then Dim ThumbPosition As Integer = CInt(e.Y - (_thumbsize / 2)) Dim ThumbBounds As Integer = Height - _thumbsize _thumby = CInt((ThumbPosition / ThumbBounds) * 100) _val = Math.Min(Math.Max(_thumby, 0), 100) Invalidate() RaiseEvent Scroll() End If End Sub Sub New() SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.Selectable Or ControlStyles.SupportsTransparentBackColor, True) DoubleBuffered = True End Sub Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs) Thumb = New Rectangle(0, 0, Width, _thumbsize) Thumb.Y = CInt(((_val) / 100) * (Height - _thumbsize)) Dim _BaseColor As Color Dim _ThumbColor As Color If _ColorScheme = ColorScheme.Dark Then _BaseColor = Color.FromArgb(64, 64, 64) _ThumbColor = Color.FromArgb(70, 70, 70) Else _BaseColor = Color.White _ThumbColor = Color.WhiteSmoke End If If Not VisibleRatio >= 1 Then Dim g = e.Graphics With g .TextRenderingHint = TextRenderingHint.ClearTypeGridFit .SmoothingMode = SmoothingMode.HighQuality .PixelOffsetMode = PixelOffsetMode.HighQuality .Clear(_BaseColor) .FillRectangle(New SolidBrush(_ThumbColor), Thumb) .DrawLine(New Pen(Color.SteelBlue, 2), New Point(CInt(Thumb.Width / 2), Thumb.Y + 4), New Point(CInt(Thumb.Width / 2), Thumb.Bottom - 4)) .InterpolationMode = InterpolationMode.HighQualityBicubic End With End If End Sub End Class