Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Strict On
- Imports System.Drawing
- Imports System.ComponentModel
- Imports System.Drawing.Drawing2D
- ''' <summary>
- ''' Advanced trackbar/progress bar with buffer support!
- ''' Fell free to COPY/EDIT/DISTRIBUTE Anything.
- ''' Made by .RazerX @HF
- ''' Many thanks to iSynthesis. I used FlatUI as a model to create this control.
- ''' http://www.hackforums.net/showthread.php?tid=3781992
- ''' </summary>
- ''' <remarks>Version 2.0.3</remarks>
- <DefaultEvent("Scrolling")> Public Class GalaxyBar : Inherits Control
- Event Scrolling()
- #Region "Variables"
- Friend G As Graphics, B As Bitmap
- Private Overlap As Rectangle
- Private Buff As Rectangle
- Private MouseBoolean As Boolean
- #End Region
- #Region "Properties"
- Dim _value As Integer = 0
- Property Value As Integer
- Set(ByVal value As Integer)
- If value = _value Then Return
- If value > _maximum OrElse value < _minimum Then
- End If
- _value = value
- Invalidate()
- End Set
- Get
- Return _value
- End Get
- End Property
- Dim _minimum As Integer = 0
- Property Minimum As Integer
- Set(ByVal value As Integer)
- If value < 0 Then value = 0
- _minimum = value
- If value > _value Then _value = value
- If value > _maximum Then _maximum = value
- Invalidate()
- End Set
- Get
- Return _minimum
- End Get
- End Property
- Dim _maximum As Integer = 100
- Property Maximum As Integer
- Set(ByVal value As Integer)
- If value < 0 Then value = 0
- _maximum = value
- If value < _value Then _value = value
- If value < _minimum Then _minimum = value
- Invalidate()
- End Set
- Get
- Return _maximum
- End Get
- End Property
- Dim _useTrackbar As Boolean = True
- Property UseTrackbar As Boolean
- Set(ByVal value As Boolean)
- _useTrackbar = value
- End Set
- Get
- Return _useTrackbar
- End Get
- End Property
- Dim _buffValue As Integer = 0
- Property BuffValue As Integer
- Set(ByVal value As Integer)
- _buffValue = value
- Invalidate()
- End Set
- Get
- Return _buffValue
- End Get
- End Property
- Dim _buffMaximum As Integer = 100
- Property BuffMaximimum As Integer
- Set(ByVal value As Integer)
- _buffMaximum = value
- Invalidate()
- End Set
- Get
- Return _buffMaximum
- End Get
- End Property
- Dim _useBuff As Boolean = False
- Property UseBuff As Boolean
- Set(ByVal value As Boolean)
- _useBuff = value
- Invalidate()
- End Set
- Get
- Return _useBuff
- End Get
- End Property
- Dim _overideBuff As Boolean = False
- Property OverideBuff As Boolean
- Set(ByVal value As Boolean)
- _overideBuff = value
- Invalidate()
- End Set
- Get
- Return _overideBuff
- End Get
- End Property
- #End Region
- #Region "Colors"
- Private _trackColor As Color = Color.Crimson
- Property TrackColor As Color
- Set(ByVal value As Color)
- _trackColor = value
- Invalidate()
- End Set
- Get
- Return _trackColor
- End Get
- End Property
- Private _BuffColor As Color = Color.FromArgb(39, 39, 46)
- Property BuffColor As Color
- Set(ByVal value As Color)
- _BuffColor = value
- Invalidate()
- End Set
- Get
- Return _BuffColor
- End Get
- End Property
- #End Region
- #Region "Mouse States"
- Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
- MyBase.OnMouseDown(e)
- MouseBoolean = True
- If _useBuff = True And _overideBuff = False Then
- If (_useTrackbar = True) And (e.X > 0) And (e.X < (Buff.Width + 2)) Then
- Value = _minimum + CInt((_maximum - _minimum) * (e.X / Width))
- RaiseEvent Scrolling()
- Invalidate()
- End If
- Else
- If (_useTrackbar = True) And (e.X > 0) And (e.X < (Width + 2)) Then
- Value = _minimum + CInt((_maximum - _minimum) * (e.X / Width))
- RaiseEvent Scrolling()
- Invalidate()
- End If
- End If
- End Sub
- Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
- MyBase.OnMouseMove(e)
- If _useBuff = True And _overideBuff = False Then
- If (_useTrackbar = True) And (e.X > 0) And (e.X < (Buff.Width + 2)) And (MouseBoolean = True) Then
- Value = _minimum + CInt((_maximum - _minimum) * (e.X / Width))
- RaiseEvent Scrolling()
- Invalidate()
- End If
- Else
- If (_useTrackbar = True) And (e.X > 0) And (e.X < (Width + 2)) And (MouseBoolean = True) Then
- Value = _minimum + CInt((_maximum - _minimum) * (e.X / Width))
- RaiseEvent Scrolling()
- Invalidate()
- End If
- End If
- End Sub
- Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
- MyBase.OnMouseUp(e) : MouseBoolean = False
- End Sub
- #End Region
- Sub New()
- SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
- ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
- DoubleBuffered = True
- Height = 20
- Width = 200
- BackColor = Color.FromArgb(32, 32, 39)
- End Sub
- Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
- B = New Bitmap(Width, Height) : G = Graphics.FromImage(B)
- Dim W As Integer = Width : Dim H As Integer = Height
- Dim Base As New Rectangle(0, 0, W, H)
- Dim GP, GP2 As New GraphicsPath
- With G
- .SmoothingMode = CType(2, SmoothingMode)
- .PixelOffsetMode = CType(2, PixelOffsetMode)
- .TextRenderingHint = CType(5, Drawing.Text.TextRenderingHint)
- .Clear(BackColor)
- '-- Calculate Values
- Dim overlapWidth As Integer = CInt((_value - _minimum) / (_maximum - _minimum) * (W))
- Overlap = New Rectangle(0, 0, overlapWidth, Height)
- If _useBuff = True Then
- Dim buffWidth As Integer = CInt((_buffValue) / (_buffMaximum) * (W))
- Buff = New Rectangle(0, 0, buffWidth, Height)
- End If
- '-- Draw Values
- GP.AddRectangle(Base)
- .SetClip(GP)
- If _useBuff = True Then .FillRectangle(New SolidBrush(_BuffColor), New Rectangle(0, 0, Buff.X + Buff.Width, Height))
- .FillRectangle(New SolidBrush(_trackColor), New Rectangle(0, 0, Overlap.X + Overlap.Width, Height))
- .ResetClip()
- End With
- MyBase.OnPaint(e)
- G.Dispose()
- e.Graphics.InterpolationMode = CType(7, InterpolationMode)
- e.Graphics.DrawImageUnscaled(B, 0, 0)
- B.Dispose()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment