RazerX

GalaxyBar v2

Nov 24th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.20 KB | None | 0 0
  1. Option Strict On
  2. Imports System.Drawing
  3. Imports System.ComponentModel
  4. Imports System.Drawing.Drawing2D
  5. ''' <summary>
  6. ''' Advanced trackbar/progress bar with buffer support!
  7. ''' Fell free to COPY/EDIT/DISTRIBUTE Anything.
  8. ''' Made by .RazerX @HF
  9. ''' Many thanks to iSynthesis. I used FlatUI as a model to create this control.
  10. ''' http://www.hackforums.net/showthread.php?tid=3781992
  11. ''' </summary>
  12. ''' <remarks>Version 2.0.3</remarks>
  13.  
  14. <DefaultEvent("Scrolling")> Public Class GalaxyBar : Inherits Control
  15.     Event Scrolling()
  16. #Region "Variables"
  17.     Friend G As Graphics, B As Bitmap
  18.     Private Overlap As Rectangle
  19.     Private Buff As Rectangle
  20.     Private MouseBoolean As Boolean
  21. #End Region
  22.  
  23. #Region "Properties"
  24.  
  25.     Dim _value As Integer = 0
  26.     Property Value As Integer
  27.         Set(ByVal value As Integer)
  28.             If value = _value Then Return
  29.             If value > _maximum OrElse value < _minimum Then
  30.             End If
  31.             _value = value
  32.             Invalidate()
  33.         End Set
  34.         Get
  35.             Return _value
  36.         End Get
  37.     End Property
  38.  
  39.     Dim _minimum As Integer = 0
  40.     Property Minimum As Integer
  41.         Set(ByVal value As Integer)
  42.             If value < 0 Then value = 0
  43.             _minimum = value
  44.             If value > _value Then _value = value
  45.             If value > _maximum Then _maximum = value
  46.             Invalidate()
  47.         End Set
  48.         Get
  49.             Return _minimum
  50.         End Get
  51.     End Property
  52.  
  53.     Dim _maximum As Integer = 100
  54.     Property Maximum As Integer
  55.         Set(ByVal value As Integer)
  56.             If value < 0 Then value = 0
  57.             _maximum = value
  58.             If value < _value Then _value = value
  59.             If value < _minimum Then _minimum = value
  60.             Invalidate()
  61.         End Set
  62.         Get
  63.             Return _maximum
  64.         End Get
  65.     End Property
  66.  
  67.     Dim _useTrackbar As Boolean = True
  68.     Property UseTrackbar As Boolean
  69.         Set(ByVal value As Boolean)
  70.             _useTrackbar = value
  71.         End Set
  72.         Get
  73.             Return _useTrackbar
  74.         End Get
  75.     End Property
  76.  
  77.     Dim _buffValue As Integer = 0
  78.     Property BuffValue As Integer
  79.         Set(ByVal value As Integer)
  80.             _buffValue = value
  81.             Invalidate()
  82.         End Set
  83.         Get
  84.             Return _buffValue
  85.         End Get
  86.     End Property
  87.  
  88.     Dim _buffMaximum As Integer = 100
  89.     Property BuffMaximimum As Integer
  90.         Set(ByVal value As Integer)
  91.             _buffMaximum = value
  92.             Invalidate()
  93.         End Set
  94.         Get
  95.             Return _buffMaximum
  96.         End Get
  97.     End Property
  98.  
  99.     Dim _useBuff As Boolean = False
  100.     Property UseBuff As Boolean
  101.         Set(ByVal value As Boolean)
  102.             _useBuff = value
  103.             Invalidate()
  104.         End Set
  105.         Get
  106.             Return _useBuff
  107.         End Get
  108.     End Property
  109.  
  110.     Dim _overideBuff As Boolean = False
  111.     Property OverideBuff As Boolean
  112.         Set(ByVal value As Boolean)
  113.             _overideBuff = value
  114.             Invalidate()
  115.         End Set
  116.         Get
  117.             Return _overideBuff
  118.         End Get
  119.     End Property
  120.  
  121.  
  122. #End Region
  123.  
  124. #Region "Colors"
  125.  
  126.     Private _trackColor As Color = Color.Crimson
  127.     Property TrackColor As Color
  128.         Set(ByVal value As Color)
  129.             _trackColor = value
  130.             Invalidate()
  131.         End Set
  132.         Get
  133.             Return _trackColor
  134.         End Get
  135.     End Property
  136.  
  137.     Private _BuffColor As Color = Color.FromArgb(39, 39, 46)
  138.     Property BuffColor As Color
  139.         Set(ByVal value As Color)
  140.             _BuffColor = value
  141.             Invalidate()
  142.         End Set
  143.         Get
  144.             Return _BuffColor
  145.         End Get
  146.     End Property
  147.  
  148. #End Region
  149.  
  150. #Region "Mouse States"
  151.  
  152.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  153.         MyBase.OnMouseDown(e)
  154.         MouseBoolean = True
  155.         If _useBuff = True And _overideBuff = False Then
  156.             If (_useTrackbar = True) And (e.X > 0) And (e.X < (Buff.Width + 2)) Then
  157.                 Value = _minimum + CInt((_maximum - _minimum) * (e.X / Width))
  158.                 RaiseEvent Scrolling()
  159.                 Invalidate()
  160.             End If
  161.         Else
  162.             If (_useTrackbar = True) And (e.X > 0) And (e.X < (Width + 2)) Then
  163.                 Value = _minimum + CInt((_maximum - _minimum) * (e.X / Width))
  164.                 RaiseEvent Scrolling()
  165.                 Invalidate()
  166.             End If
  167.         End If
  168.     End Sub
  169.  
  170.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  171.         MyBase.OnMouseMove(e)
  172.         If _useBuff = True And _overideBuff = False Then
  173.             If (_useTrackbar = True) And (e.X > 0) And (e.X < (Buff.Width + 2)) And (MouseBoolean = True) Then
  174.                 Value = _minimum + CInt((_maximum - _minimum) * (e.X / Width))
  175.                 RaiseEvent Scrolling()
  176.                 Invalidate()
  177.             End If
  178.         Else
  179.             If (_useTrackbar = True) And (e.X > 0) And (e.X < (Width + 2)) And (MouseBoolean = True) Then
  180.                 Value = _minimum + CInt((_maximum - _minimum) * (e.X / Width))
  181.                 RaiseEvent Scrolling()
  182.                 Invalidate()
  183.             End If
  184.         End If
  185.     End Sub
  186.  
  187.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  188.         MyBase.OnMouseUp(e) : MouseBoolean = False
  189.     End Sub
  190.  
  191. #End Region
  192.  
  193.     Sub New()
  194.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
  195.                  ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
  196.         DoubleBuffered = True
  197.         Height = 20
  198.         Width = 200
  199.         BackColor = Color.FromArgb(32, 32, 39)
  200.     End Sub
  201.  
  202.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  203.         B = New Bitmap(Width, Height) : G = Graphics.FromImage(B)
  204.         Dim W As Integer = Width : Dim H As Integer = Height
  205.  
  206.         Dim Base As New Rectangle(0, 0, W, H)
  207.         Dim GP, GP2 As New GraphicsPath
  208.  
  209.         With G
  210.             .SmoothingMode = CType(2, SmoothingMode)
  211.             .PixelOffsetMode = CType(2, PixelOffsetMode)
  212.             .TextRenderingHint = CType(5, Drawing.Text.TextRenderingHint)
  213.             .Clear(BackColor)
  214.  
  215.             '-- Calculate Values
  216.             Dim overlapWidth As Integer = CInt((_value - _minimum) / (_maximum - _minimum) * (W))
  217.             Overlap = New Rectangle(0, 0, overlapWidth, Height)
  218.             If _useBuff = True Then
  219.                 Dim buffWidth As Integer = CInt((_buffValue) / (_buffMaximum) * (W))
  220.                 Buff = New Rectangle(0, 0, buffWidth, Height)
  221.             End If
  222.  
  223.             '-- Draw Values
  224.             GP.AddRectangle(Base)
  225.             .SetClip(GP)
  226.             If _useBuff = True Then .FillRectangle(New SolidBrush(_BuffColor), New Rectangle(0, 0, Buff.X + Buff.Width, Height))
  227.             .FillRectangle(New SolidBrush(_trackColor), New Rectangle(0, 0, Overlap.X + Overlap.Width, Height))
  228.             .ResetClip()
  229.         End With
  230.  
  231.         MyBase.OnPaint(e)
  232.         G.Dispose()
  233.         e.Graphics.InterpolationMode = CType(7, InterpolationMode)
  234.         e.Graphics.DrawImageUnscaled(B, 0, 0)
  235.         B.Dispose()
  236.     End Sub
  237. End Class
Advertisement
Add Comment
Please, Sign In to add comment