TWIXXZOR

5Gz VB Theme v3

Dec 22nd, 2011
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System, System.IO, System.Collections.Generic
  2. Imports System.Drawing, System.Drawing.Drawing2D
  3. Imports System.ComponentModel, System.Windows.Forms
  4. Imports System.Runtime.InteropServices
  5. Imports System.Drawing.Imaging
  6. MustInherit Class ThemeContainer153
  7.     Inherits ContainerControl
  8.  
  9. #Region " Initialization "
  10.  
  11.     Protected G As Graphics, B As Bitmap
  12.  
  13.     Sub New()
  14.         SetStyle(DirectCast(139270, ControlStyles), True)
  15.  
  16.         _ImageSize = Size.Empty
  17.         Font = New Font("Verdana", 8S)
  18.  
  19.         MeasureBitmap = New Bitmap(1, 1)
  20.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  21.  
  22.         DrawRadialPath = New GraphicsPath
  23.  
  24.         InvalidateCustimization() 'Remove?
  25.    End Sub
  26.  
  27.     Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  28.         InvalidateCustimization()
  29.         ColorHook()
  30.  
  31.         If Not _LockWidth = 0 Then Width = _LockWidth
  32.         If Not _LockHeight = 0 Then Height = _LockHeight
  33.         If Not _ControlMode Then MyBase.Dock = DockStyle.Fill
  34.  
  35.         Transparent = _Transparent
  36.         If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  37.  
  38.         MyBase.OnHandleCreated(e)
  39.     End Sub
  40.  
  41.     Protected NotOverridable Overrides Sub OnParentChanged(ByVal e As EventArgs)
  42.         MyBase.OnParentChanged(e)
  43.  
  44.         If Parent Is Nothing Then Return
  45.         _IsParentForm = TypeOf Parent Is Form
  46.  
  47.         If Not _ControlMode Then
  48.             InitializeMessages()
  49.  
  50.             If _IsParentForm Then
  51.                 ParentForm.FormBorderStyle = _BorderStyle
  52.                 ParentForm.TransparencyKey = _TransparencyKey
  53.             End If
  54.  
  55.             Parent.BackColor = BackColor
  56.         End If
  57.  
  58.         OnCreation()
  59.     End Sub
  60.  
  61. #End Region
  62.  
  63.  
  64.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  65.         If Width = 0 OrElse Height = 0 Then Return
  66.  
  67.         If _Transparent AndAlso _ControlMode Then
  68.             PaintHook()
  69.             e.Graphics.DrawImage(B, 0, 0)
  70.         Else
  71.             G = e.Graphics
  72.             PaintHook()
  73.         End If
  74.     End Sub
  75.  
  76.  
  77. #Region " Size Handling "
  78.  
  79.     Private Frame As Rectangle
  80.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  81.         If _Movable AndAlso Not _ControlMode Then
  82.             Frame = New Rectangle(7, 7, Width - 14, _Header - 7)
  83.         End If
  84.  
  85.         InvalidateBitmap()
  86.         Invalidate()
  87.  
  88.         MyBase.OnSizeChanged(e)
  89.     End Sub
  90.  
  91.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  92.         If Not _LockWidth = 0 Then width = _LockWidth
  93.         If Not _LockHeight = 0 Then height = _LockHeight
  94.         MyBase.SetBoundsCore(x, y, width, height, specified)
  95.     End Sub
  96.  
  97. #End Region
  98.  
  99. #Region " State Handling "
  100.  
  101.     Protected State As MouseState
  102.     Private Sub SetState(ByVal current As MouseState)
  103.         State = current
  104.         Invalidate()
  105.     End Sub
  106.  
  107.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  108.         If Not (_IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized) Then
  109.             If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  110.         End If
  111.  
  112.         MyBase.OnMouseMove(e)
  113.     End Sub
  114.  
  115.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  116.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  117.         MyBase.OnEnabledChanged(e)
  118.     End Sub
  119.  
  120.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  121.         SetState(MouseState.Over)
  122.         MyBase.OnMouseEnter(e)
  123.     End Sub
  124.  
  125.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  126.         SetState(MouseState.Over)
  127.         MyBase.OnMouseUp(e)
  128.     End Sub
  129.  
  130.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  131.         SetState(MouseState.None)
  132.  
  133.         If GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  134.             If _Sizable AndAlso Not _ControlMode Then
  135.                 Cursor = Cursors.Default
  136.                 Previous = 0
  137.             End If
  138.         End If
  139.  
  140.         MyBase.OnMouseLeave(e)
  141.     End Sub
  142.  
  143.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  144.         If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  145.  
  146.         If Not (_IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode) Then
  147.             If _Movable AndAlso Frame.Contains(e.Location) Then
  148.                 Capture = False
  149.                 WM_LMBUTTONDOWN = True
  150.                 DefWndProc(Messages(0))
  151.             ElseIf _Sizable AndAlso Not Previous = 0 Then
  152.                 Capture = False
  153.                 WM_LMBUTTONDOWN = True
  154.                 DefWndProc(Messages(Previous))
  155.             End If
  156.         End If
  157.  
  158.         MyBase.OnMouseDown(e)
  159.     End Sub
  160.  
  161.     Private WM_LMBUTTONDOWN As Boolean
  162.     Protected Overrides Sub WndProc(ByRef m As Message)
  163.         MyBase.WndProc(m)
  164.  
  165.         If WM_LMBUTTONDOWN AndAlso m.Msg = 513 Then
  166.             WM_LMBUTTONDOWN = False
  167.  
  168.             SetState(MouseState.Over)
  169.             If Not _SmartBounds Then Return
  170.  
  171.             If IsParentMdi Then
  172.                 CorrectBounds(New Rectangle(Point.Empty, Parent.Parent.Size))
  173.             Else
  174.                 CorrectBounds(Screen.FromControl(Parent).WorkingArea)
  175.             End If
  176.         End If
  177.     End Sub
  178.  
  179.     Private GetIndexPoint As Point
  180.     Private B1, B2, B3, B4 As Boolean
  181.     Private Function GetIndex() As Integer
  182.         GetIndexPoint = PointToClient(MousePosition)
  183.         B1 = GetIndexPoint.X < 7
  184.         B2 = GetIndexPoint.X > Width - 7
  185.         B3 = GetIndexPoint.Y < 7
  186.         B4 = GetIndexPoint.Y > Height - 7
  187.  
  188.         If B1 AndAlso B3 Then Return 4
  189.         If B1 AndAlso B4 Then Return 7
  190.         If B2 AndAlso B3 Then Return 5
  191.         If B2 AndAlso B4 Then Return 8
  192.         If B1 Then Return 1
  193.         If B2 Then Return 2
  194.         If B3 Then Return 3
  195.         If B4 Then Return 6
  196.         Return 0
  197.     End Function
  198.  
  199.     Private Current, Previous As Integer
  200.     Private Sub InvalidateMouse()
  201.         Current = GetIndex()
  202.         If Current = Previous Then Return
  203.  
  204.         Previous = Current
  205.         Select Case Previous
  206.             Case 0
  207.                 Cursor = Cursors.Default
  208.             Case 1, 2
  209.                 Cursor = Cursors.SizeWE
  210.             Case 3, 6
  211.                 Cursor = Cursors.SizeNS
  212.             Case 4, 8
  213.                 Cursor = Cursors.SizeNWSE
  214.             Case 5, 7
  215.                 Cursor = Cursors.SizeNESW
  216.         End Select
  217.     End Sub
  218.  
  219.     Private Messages(8) As Message
  220.     Private Sub InitializeMessages()
  221.         Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  222.         For I As Integer = 1 To 8
  223.             Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  224.         Next
  225.     End Sub
  226.  
  227.     Private Sub CorrectBounds(ByVal bounds As Rectangle)
  228.         If Parent.Width > bounds.Width Then Parent.Width = bounds.Width
  229.         If Parent.Height > bounds.Height Then Parent.Height = bounds.Height
  230.  
  231.         Dim X As Integer = Parent.Location.X
  232.         Dim Y As Integer = Parent.Location.Y
  233.  
  234.         If X < bounds.X Then X = bounds.X
  235.         If Y < bounds.Y Then Y = bounds.Y
  236.  
  237.         Dim Width As Integer = bounds.X + bounds.Width
  238.         Dim Height As Integer = bounds.Y + bounds.Height
  239.  
  240.         If X + Parent.Width > Width Then X = Width - Parent.Width
  241.         If Y + Parent.Height > Height Then Y = Height - Parent.Height
  242.  
  243.         Parent.Location = New Point(X, Y)
  244.     End Sub
  245.  
  246. #End Region
  247.  
  248.  
  249. #Region " Base Properties "
  250.  
  251.     Overrides Property Dock As DockStyle
  252.         Get
  253.             Return MyBase.Dock
  254.         End Get
  255.         Set(ByVal value As DockStyle)
  256.             If Not _ControlMode Then Return
  257.             MyBase.Dock = value
  258.         End Set
  259.     End Property
  260.  
  261.     Private _BackColor As Boolean
  262.     <Category("Misc")> _
  263.     Overrides Property BackColor() As Color
  264.         Get
  265.             Return MyBase.BackColor
  266.         End Get
  267.         Set(ByVal value As Color)
  268.             If value = MyBase.BackColor Then Return
  269.  
  270.             If Not IsHandleCreated AndAlso _ControlMode AndAlso value = Color.Transparent Then
  271.                 _BackColor = True
  272.                 Return
  273.             End If
  274.  
  275.             MyBase.BackColor = value
  276.             If Parent IsNot Nothing Then
  277.                 If Not _ControlMode Then Parent.BackColor = value
  278.                 ColorHook()
  279.             End If
  280.         End Set
  281.     End Property
  282.  
  283.     Overrides Property MinimumSize As Size
  284.         Get
  285.             Return MyBase.MinimumSize
  286.         End Get
  287.         Set(ByVal value As Size)
  288.             MyBase.MinimumSize = value
  289.             If Parent IsNot Nothing Then Parent.MinimumSize = value
  290.         End Set
  291.     End Property
  292.  
  293.     Overrides Property MaximumSize As Size
  294.         Get
  295.             Return MyBase.MaximumSize
  296.         End Get
  297.         Set(ByVal value As Size)
  298.             MyBase.MaximumSize = value
  299.             If Parent IsNot Nothing Then Parent.MaximumSize = value
  300.         End Set
  301.     End Property
  302.  
  303.     Overrides Property Text() As String
  304.         Get
  305.             Return MyBase.Text
  306.         End Get
  307.         Set(ByVal value As String)
  308.             MyBase.Text = value
  309.             Invalidate()
  310.         End Set
  311.     End Property
  312.  
  313.     Overrides Property Font() As Font
  314.         Get
  315.             Return MyBase.Font
  316.         End Get
  317.         Set(ByVal value As Font)
  318.             MyBase.Font = value
  319.             Invalidate()
  320.         End Set
  321.     End Property
  322.  
  323.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  324.     Overrides Property ForeColor() As Color
  325.         Get
  326.             Return Color.Empty
  327.         End Get
  328.         Set(ByVal value As Color)
  329.         End Set
  330.     End Property
  331.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  332.     Overrides Property BackgroundImage() As Image
  333.         Get
  334.             Return Nothing
  335.         End Get
  336.         Set(ByVal value As Image)
  337.         End Set
  338.     End Property
  339.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  340.     Overrides Property BackgroundImageLayout() As ImageLayout
  341.         Get
  342.             Return ImageLayout.None
  343.         End Get
  344.         Set(ByVal value As ImageLayout)
  345.         End Set
  346.     End Property
  347.  
  348. #End Region
  349.  
  350. #Region " Public Properties "
  351.  
  352.     Private _SmartBounds As Boolean = True
  353.     Property SmartBounds() As Boolean
  354.         Get
  355.             Return _SmartBounds
  356.         End Get
  357.         Set(ByVal value As Boolean)
  358.             _SmartBounds = value
  359.         End Set
  360.     End Property
  361.  
  362.     Private _Movable As Boolean = True
  363.     Property Movable() As Boolean
  364.         Get
  365.             Return _Movable
  366.         End Get
  367.         Set(ByVal value As Boolean)
  368.             _Movable = value
  369.         End Set
  370.     End Property
  371.  
  372.     Private _Sizable As Boolean = True
  373.     Property Sizable() As Boolean
  374.         Get
  375.             Return _Sizable
  376.         End Get
  377.         Set(ByVal value As Boolean)
  378.             _Sizable = value
  379.         End Set
  380.     End Property
  381.  
  382.     Private _TransparencyKey As Color
  383.     Property TransparencyKey() As Color
  384.         Get
  385.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  386.         End Get
  387.         Set(ByVal value As Color)
  388.             If value = _TransparencyKey Then Return
  389.             _TransparencyKey = value
  390.  
  391.             If _IsParentForm AndAlso Not _ControlMode Then
  392.                 ParentForm.TransparencyKey = value
  393.                 ColorHook()
  394.             End If
  395.         End Set
  396.     End Property
  397.  
  398.     Private _BorderStyle As FormBorderStyle
  399.     Property BorderStyle() As FormBorderStyle
  400.         Get
  401.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  402.         End Get
  403.         Set(ByVal value As FormBorderStyle)
  404.             _BorderStyle = value
  405.  
  406.             If _IsParentForm AndAlso Not _ControlMode Then
  407.                 ParentForm.FormBorderStyle = value
  408.  
  409.                 If Not value = FormBorderStyle.None Then
  410.                     Movable = False
  411.                     Sizable = False
  412.                 End If
  413.             End If
  414.         End Set
  415.     End Property
  416.  
  417.     Private _NoRounding As Boolean
  418.     Property NoRounding() As Boolean
  419.         Get
  420.             Return _NoRounding
  421.         End Get
  422.         Set(ByVal v As Boolean)
  423.             _NoRounding = v
  424.             Invalidate()
  425.         End Set
  426.     End Property
  427.  
  428.     Private _Image As Image
  429.     Property Image() As Image
  430.         Get
  431.             Return _Image
  432.         End Get
  433.         Set(ByVal value As Image)
  434.             If value Is Nothing Then _ImageSize = Size.Empty Else _ImageSize = value.Size
  435.  
  436.             _Image = value
  437.             Invalidate()
  438.         End Set
  439.     End Property
  440.  
  441.     Private Items As New Dictionary(Of String, Color)
  442.     Property Colors() As Bloom()
  443.         Get
  444.             Dim T As New List(Of Bloom)
  445.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  446.  
  447.             While E.MoveNext
  448.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  449.             End While
  450.  
  451.             Return T.ToArray
  452.         End Get
  453.         Set(ByVal value As Bloom())
  454.             For Each B As Bloom In value
  455.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  456.             Next
  457.  
  458.             InvalidateCustimization()
  459.             ColorHook()
  460.             Invalidate()
  461.         End Set
  462.     End Property
  463.  
  464.     Private _Customization As String
  465.     Property Customization() As String
  466.         Get
  467.             Return _Customization
  468.         End Get
  469.         Set(ByVal value As String)
  470.             If value = _Customization Then Return
  471.  
  472.             Dim Data As Byte()
  473.             Dim Items As Bloom() = Colors
  474.  
  475.             Try
  476.                 Data = Convert.FromBase64String(value)
  477.                 For I As Integer = 0 To Items.Length - 1
  478.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  479.                 Next
  480.             Catch
  481.                 Return
  482.             End Try
  483.  
  484.             _Customization = value
  485.  
  486.             Colors = Items
  487.             ColorHook()
  488.             Invalidate()
  489.         End Set
  490.     End Property
  491.  
  492.     Private _Transparent As Boolean
  493.     Property Transparent() As Boolean
  494.         Get
  495.             Return _Transparent
  496.         End Get
  497.         Set(ByVal value As Boolean)
  498.             _Transparent = value
  499.             If Not (IsHandleCreated OrElse _ControlMode) Then Return
  500.  
  501.             If Not value AndAlso Not BackColor.A = 255 Then
  502.                 Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  503.             End If
  504.  
  505.             SetStyle(ControlStyles.Opaque, Not value)
  506.             SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  507.  
  508.             InvalidateBitmap()
  509.             Invalidate()
  510.         End Set
  511.     End Property
  512.  
  513. #End Region
  514.  
  515. #Region " Private Properties "
  516.  
  517.     Private _ImageSize As Size
  518.     Protected ReadOnly Property ImageSize() As Size
  519.         Get
  520.             Return _ImageSize
  521.         End Get
  522.     End Property
  523.  
  524.     Private _IsParentForm As Boolean
  525.     Protected ReadOnly Property IsParentForm As Boolean
  526.         Get
  527.             Return _IsParentForm
  528.         End Get
  529.     End Property
  530.  
  531.     Protected ReadOnly Property IsParentMdi As Boolean
  532.         Get
  533.             If Parent Is Nothing Then Return False
  534.             Return Parent.Parent IsNot Nothing
  535.         End Get
  536.     End Property
  537.  
  538.     Private _LockWidth As Integer
  539.     Protected Property LockWidth() As Integer
  540.         Get
  541.             Return _LockWidth
  542.         End Get
  543.         Set(ByVal value As Integer)
  544.             _LockWidth = value
  545.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  546.         End Set
  547.     End Property
  548.  
  549.     Private _LockHeight As Integer
  550.     Protected Property LockHeight() As Integer
  551.         Get
  552.             Return _LockHeight
  553.         End Get
  554.         Set(ByVal value As Integer)
  555.             _LockHeight = value
  556.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  557.         End Set
  558.     End Property
  559.  
  560.     Private _Header As Integer = 24
  561.     Protected Property Header() As Integer
  562.         Get
  563.             Return _Header
  564.         End Get
  565.         Set(ByVal v As Integer)
  566.             _Header = v
  567.  
  568.             If Not _ControlMode Then
  569.                 Frame = New Rectangle(7, 7, Width - 14, v - 7)
  570.                 Invalidate()
  571.             End If
  572.         End Set
  573.     End Property
  574.  
  575.     Private _ControlMode As Boolean
  576.     Protected Property ControlMode() As Boolean
  577.         Get
  578.             Return _ControlMode
  579.         End Get
  580.         Set(ByVal v As Boolean)
  581.             _ControlMode = v
  582.  
  583.             Transparent = _Transparent
  584.             If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  585.  
  586.             InvalidateBitmap()
  587.             Invalidate()
  588.         End Set
  589.     End Property
  590.  
  591. #End Region
  592.  
  593.  
  594. #Region " Property Helpers "
  595.  
  596.     Protected Function GetPen(ByVal name As String) As Pen
  597.         Return New Pen(Items(name))
  598.     End Function
  599.     Protected Function GetPen(ByVal name As String, ByVal width As Single) As Pen
  600.         Return New Pen(Items(name), width)
  601.     End Function
  602.  
  603.     Protected Function GetBrush(ByVal name As String) As SolidBrush
  604.         Return New SolidBrush(Items(name))
  605.     End Function
  606.  
  607.     Protected Function GetColor(ByVal name As String) As Color
  608.         Return Items(name)
  609.     End Function
  610.  
  611.     Protected Sub SetColor(ByVal name As String, ByVal value As Color)
  612.         If Items.ContainsKey(name) Then Items(name) = value Else Items.Add(name, value)
  613.     End Sub
  614.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  615.         SetColor(name, Color.FromArgb(r, g, b))
  616.     End Sub
  617.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  618.         SetColor(name, Color.FromArgb(a, r, g, b))
  619.     End Sub
  620.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal value As Color)
  621.         SetColor(name, Color.FromArgb(a, value))
  622.     End Sub
  623.  
  624.     Private Sub InvalidateBitmap()
  625.         If _Transparent AndAlso _ControlMode Then
  626.             If Width = 0 OrElse Height = 0 Then Return
  627.             B = New Bitmap(Width, Height, PixelFormat.Format32bppPArgb)
  628.             G = Graphics.FromImage(B)
  629.         Else
  630.             G = Nothing
  631.             B = Nothing
  632.         End If
  633.     End Sub
  634.  
  635.     Private Sub InvalidateCustimization()
  636.         Dim M As New MemoryStream(Items.Count * 4)
  637.  
  638.         For Each B As Bloom In Colors
  639.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  640.         Next
  641.  
  642.         M.Close()
  643.         _Customization = Convert.ToBase64String(M.ToArray)
  644.     End Sub
  645.  
  646. #End Region
  647.  
  648.  
  649. #Region " User Hooks "
  650.  
  651.     Protected MustOverride Sub ColorHook()
  652.     Protected MustOverride Sub PaintHook()
  653.  
  654.     Protected Overridable Sub OnCreation()
  655.     End Sub
  656.  
  657. #End Region
  658.  
  659.  
  660. #Region " Offset "
  661.  
  662.     Private OffsetReturnRectangle As Rectangle
  663.     Protected Function Offset(ByVal r As Rectangle, ByVal amount As Integer) As Rectangle
  664.         OffsetReturnRectangle = New Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2))
  665.         Return OffsetReturnRectangle
  666.     End Function
  667.  
  668.     Private OffsetReturnSize As Size
  669.     Protected Function Offset(ByVal s As Size, ByVal amount As Integer) As Size
  670.         OffsetReturnSize = New Size(s.Width + amount, s.Height + amount)
  671.         Return OffsetReturnSize
  672.     End Function
  673.  
  674.     Private OffsetReturnPoint As Point
  675.     Protected Function Offset(ByVal p As Point, ByVal amount As Integer) As Point
  676.         OffsetReturnPoint = New Point(p.X + amount, p.Y + amount)
  677.         Return OffsetReturnPoint
  678.     End Function
  679.  
  680. #End Region
  681.  
  682. #Region " Center "
  683.  
  684.     Private CenterReturn As Point
  685.  
  686.     Protected Function Center(ByVal p As Rectangle, ByVal c As Rectangle) As Point
  687.         CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X + c.X, (p.Height \ 2 - c.Height \ 2) + p.Y + c.Y)
  688.         Return CenterReturn
  689.     End Function
  690.     Protected Function Center(ByVal p As Rectangle, ByVal c As Size) As Point
  691.         CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X, (p.Height \ 2 - c.Height \ 2) + p.Y)
  692.         Return CenterReturn
  693.     End Function
  694.  
  695.     Protected Function Center(ByVal child As Rectangle) As Point
  696.         Return Center(Width, Height, child.Width, child.Height)
  697.     End Function
  698.     Protected Function Center(ByVal child As Size) As Point
  699.         Return Center(Width, Height, child.Width, child.Height)
  700.     End Function
  701.     Protected Function Center(ByVal childWidth As Integer, ByVal childHeight As Integer) As Point
  702.         Return Center(Width, Height, childWidth, childHeight)
  703.     End Function
  704.  
  705.     Protected Function Center(ByVal p As Size, ByVal c As Size) As Point
  706.         Return Center(p.Width, p.Height, c.Width, c.Height)
  707.     End Function
  708.  
  709.     Protected Function Center(ByVal pWidth As Integer, ByVal pHeight As Integer, ByVal cWidth As Integer, ByVal cHeight As Integer) As Point
  710.         CenterReturn = New Point(pWidth \ 2 - cWidth \ 2, pHeight \ 2 - cHeight \ 2)
  711.         Return CenterReturn
  712.     End Function
  713.  
  714. #End Region
  715.  
  716. #Region " Measure "
  717.  
  718.     Private MeasureBitmap As Bitmap
  719.     Private MeasureGraphics As Graphics 'TODO: Potential issues during multi-threading.
  720.  
  721.     Protected Function Measure() As Size
  722.         Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  723.     End Function
  724.     Protected Function Measure(ByVal text As String) As Size
  725.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  726.     End Function
  727.  
  728. #End Region
  729.  
  730.  
  731. #Region " DrawPixel "
  732.  
  733.     Private DrawPixelBrush As SolidBrush
  734.  
  735.     Protected Sub DrawPixel(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer)
  736.         If _Transparent Then
  737.             B.SetPixel(x, y, c1)
  738.         Else
  739.             DrawPixelBrush = New SolidBrush(c1)
  740.             G.FillRectangle(DrawPixelBrush, x, y, 1, 1)
  741.         End If
  742.     End Sub
  743.  
  744. #End Region
  745.  
  746. #Region " DrawCorners "
  747.  
  748.     Private DrawCornersBrush As SolidBrush
  749.  
  750.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal offset As Integer)
  751.         DrawCorners(c1, 0, 0, Width, Height, offset)
  752.     End Sub
  753.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle, ByVal offset As Integer)
  754.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset)
  755.     End Sub
  756.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  757.         DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  758.     End Sub
  759.  
  760.     Protected Sub DrawCorners(ByVal c1 As Color)
  761.         DrawCorners(c1, 0, 0, Width, Height)
  762.     End Sub
  763.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  764.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  765.     End Sub
  766.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  767.         If _NoRounding Then Return
  768.  
  769.         If _Transparent Then
  770.             B.SetPixel(x, y, c1)
  771.             B.SetPixel(x + (width - 1), y, c1)
  772.             B.SetPixel(x, y + (height - 1), c1)
  773.             B.SetPixel(x + (width - 1), y + (height - 1), c1)
  774.         Else
  775.             DrawCornersBrush = New SolidBrush(c1)
  776.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  777.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  778.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  779.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  780.         End If
  781.     End Sub
  782.  
  783. #End Region
  784.  
  785. #Region " DrawBorders "
  786.  
  787.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  788.         DrawBorders(p1, 0, 0, Width, Height, offset)
  789.     End Sub
  790.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  791.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  792.     End Sub
  793.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  794.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  795.     End Sub
  796.  
  797.     Protected Sub DrawBorders(ByVal p1 As Pen)
  798.         DrawBorders(p1, 0, 0, Width, Height)
  799.     End Sub
  800.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  801.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  802.     End Sub
  803.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  804.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  805.     End Sub
  806.  
  807. #End Region
  808.  
  809. #Region " DrawText "
  810.  
  811.     Private DrawTextPoint As Point
  812.     Private DrawTextSize As Size
  813.  
  814.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  815.         DrawText(b1, Text, a, x, y)
  816.     End Sub
  817.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  818.         If text.Length = 0 Then Return
  819.  
  820.         DrawTextSize = Measure(text)
  821.         DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, Header \ 2 - DrawTextSize.Height \ 2)
  822.  
  823.         Select Case a
  824.             Case HorizontalAlignment.Left
  825.                 G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y)
  826.             Case HorizontalAlignment.Center
  827.                 G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  828.             Case HorizontalAlignment.Right
  829.                 G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  830.         End Select
  831.     End Sub
  832.  
  833.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  834.         If Text.Length = 0 Then Return
  835.         G.DrawString(Text, Font, b1, p1)
  836.     End Sub
  837.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  838.         If Text.Length = 0 Then Return
  839.         G.DrawString(Text, Font, b1, x, y)
  840.     End Sub
  841.  
  842. #End Region
  843.  
  844. #Region " DrawImage "
  845.  
  846.     Private DrawImagePoint As Point
  847.  
  848.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  849.         DrawImage(_Image, a, x, y)
  850.     End Sub
  851.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  852.         If image Is Nothing Then Return
  853.         DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, Header \ 2 - image.Height \ 2)
  854.  
  855.         Select Case a
  856.             Case HorizontalAlignment.Left
  857.                 G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height)
  858.             Case HorizontalAlignment.Center
  859.                 G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height)
  860.             Case HorizontalAlignment.Right
  861.                 G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height)
  862.         End Select
  863.     End Sub
  864.  
  865.     Protected Sub DrawImage(ByVal p1 As Point)
  866.         DrawImage(_Image, p1.X, p1.Y)
  867.     End Sub
  868.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  869.         DrawImage(_Image, x, y)
  870.     End Sub
  871.  
  872.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  873.         DrawImage(image, p1.X, p1.Y)
  874.     End Sub
  875.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  876.         If image Is Nothing Then Return
  877.         G.DrawImage(image, x, y, image.Width, image.Height)
  878.     End Sub
  879.  
  880. #End Region
  881.  
  882. #Region " DrawGradient "
  883.  
  884.     Private DrawGradientBrush As LinearGradientBrush
  885.     Private DrawGradientRectangle As Rectangle
  886.  
  887.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  888.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  889.         DrawGradient(blend, DrawGradientRectangle)
  890.     End Sub
  891.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  892.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  893.         DrawGradient(blend, DrawGradientRectangle, angle)
  894.     End Sub
  895.  
  896.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle)
  897.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, 90.0F)
  898.         DrawGradientBrush.InterpolationColors = blend
  899.         G.FillRectangle(DrawGradientBrush, r)
  900.     End Sub
  901.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  902.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  903.         DrawGradientBrush.InterpolationColors = blend
  904.         G.FillRectangle(DrawGradientBrush, r)
  905.     End Sub
  906.  
  907.  
  908.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  909.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  910.         DrawGradient(c1, c2, DrawGradientRectangle)
  911.     End Sub
  912.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  913.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  914.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  915.     End Sub
  916.  
  917.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  918.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, 90.0F)
  919.         G.FillRectangle(DrawGradientBrush, r)
  920.     End Sub
  921.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  922.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  923.         G.FillRectangle(DrawGradientBrush, r)
  924.     End Sub
  925.  
  926. #End Region
  927.  
  928. #Region " DrawRadial "
  929.  
  930.     Private DrawRadialPath As GraphicsPath
  931.     Private DrawRadialBrush1 As PathGradientBrush
  932.     Private DrawRadialBrush2 As LinearGradientBrush
  933.     Private DrawRadialRectangle As Rectangle
  934.  
  935.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  936.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  937.         DrawRadial(blend, DrawRadialRectangle, width \ 2, height \ 2)
  938.     End Sub
  939.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal center As Point)
  940.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  941.         DrawRadial(blend, DrawRadialRectangle, center.X, center.Y)
  942.     End Sub
  943.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal cx As Integer, ByVal cy As Integer)
  944.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  945.         DrawRadial(blend, DrawRadialRectangle, cx, cy)
  946.     End Sub
  947.  
  948.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle)
  949.         DrawRadial(blend, r, r.Width \ 2, r.Height \ 2)
  950.     End Sub
  951.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal center As Point)
  952.         DrawRadial(blend, r, center.X, center.Y)
  953.     End Sub
  954.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal cx As Integer, ByVal cy As Integer)
  955.         DrawRadialPath.Reset()
  956.         DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1)
  957.  
  958.         DrawRadialBrush1 = New PathGradientBrush(DrawRadialPath)
  959.         DrawRadialBrush1.CenterPoint = New Point(r.X + cx, r.Y + cy)
  960.         DrawRadialBrush1.InterpolationColors = blend
  961.  
  962.         If G.SmoothingMode = SmoothingMode.AntiAlias Then
  963.             G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3)
  964.         Else
  965.             G.FillEllipse(DrawRadialBrush1, r)
  966.         End If
  967.     End Sub
  968.  
  969.  
  970.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  971.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  972.         DrawRadial(c1, c2, DrawGradientRectangle)
  973.     End Sub
  974.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  975.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  976.         DrawRadial(c1, c2, DrawGradientRectangle, angle)
  977.     End Sub
  978.  
  979.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  980.         DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, 90.0F)
  981.         G.FillRectangle(DrawGradientBrush, r)
  982.     End Sub
  983.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  984.         DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, angle)
  985.         G.FillEllipse(DrawGradientBrush, r)
  986.     End Sub
  987.  
  988. #End Region
  989.  
  990. End Class
  991. MustInherit Class ThemeControl153
  992.     Inherits Control
  993.  
  994.  
  995. #Region " Initialization "
  996.  
  997.     Protected G As Graphics, B As Bitmap
  998.  
  999.     Sub New()
  1000.         SetStyle(DirectCast(139270, ControlStyles), True)
  1001.  
  1002.         _ImageSize = Size.Empty
  1003.         Font = New Font("Verdana", 8S)
  1004.  
  1005.         MeasureBitmap = New Bitmap(1, 1)
  1006.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  1007.  
  1008.         DrawRadialPath = New GraphicsPath
  1009.  
  1010.         InvalidateCustimization() 'Remove?
  1011.    End Sub
  1012.  
  1013.     Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  1014.         InvalidateCustimization()
  1015.         ColorHook()
  1016.  
  1017.         If Not _LockWidth = 0 Then Width = _LockWidth
  1018.         If Not _LockHeight = 0 Then Height = _LockHeight
  1019.  
  1020.         Transparent = _Transparent
  1021.         If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  1022.  
  1023.         MyBase.OnHandleCreated(e)
  1024.     End Sub
  1025.  
  1026.     Protected NotOverridable Overrides Sub OnParentChanged(ByVal e As EventArgs)
  1027.         If Parent IsNot Nothing Then OnCreation()
  1028.         MyBase.OnParentChanged(e)
  1029.     End Sub
  1030.  
  1031. #End Region
  1032.  
  1033.  
  1034.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  1035.         If Width = 0 OrElse Height = 0 Then Return
  1036.  
  1037.         If _Transparent Then
  1038.             PaintHook()
  1039.             e.Graphics.DrawImage(B, 0, 0)
  1040.         Else
  1041.             G = e.Graphics
  1042.             PaintHook()
  1043.         End If
  1044.     End Sub
  1045.  
  1046.  
  1047. #Region " Size Handling "
  1048.  
  1049.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  1050.         If _Transparent Then
  1051.             InvalidateBitmap()
  1052.         End If
  1053.  
  1054.         Invalidate()
  1055.         MyBase.OnSizeChanged(e)
  1056.     End Sub
  1057.  
  1058.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  1059.         If Not _LockWidth = 0 Then width = _LockWidth
  1060.         If Not _LockHeight = 0 Then height = _LockHeight
  1061.         MyBase.SetBoundsCore(x, y, width, height, specified)
  1062.     End Sub
  1063.  
  1064. #End Region
  1065.  
  1066. #Region " State Handling "
  1067.  
  1068.     Private InPosition As Boolean
  1069.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  1070.         InPosition = True
  1071.         SetState(MouseState.Over)
  1072.         MyBase.OnMouseEnter(e)
  1073.     End Sub
  1074.  
  1075.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  1076.         If InPosition Then SetState(MouseState.Over)
  1077.         MyBase.OnMouseUp(e)
  1078.     End Sub
  1079.  
  1080.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  1081.         If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  1082.         MyBase.OnMouseDown(e)
  1083.     End Sub
  1084.  
  1085.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  1086.         InPosition = False
  1087.         SetState(MouseState.None)
  1088.         MyBase.OnMouseLeave(e)
  1089.     End Sub
  1090.  
  1091.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  1092.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  1093.         MyBase.OnEnabledChanged(e)
  1094.     End Sub
  1095.  
  1096.     Protected State As MouseState
  1097.     Private Sub SetState(ByVal current As MouseState)
  1098.         State = current
  1099.         Invalidate()
  1100.     End Sub
  1101.  
  1102. #End Region
  1103.  
  1104.  
  1105. #Region " Base Properties "
  1106.  
  1107.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1108.     Overrides Property ForeColor() As Color
  1109.         Get
  1110.             Return Color.Empty
  1111.         End Get
  1112.         Set(ByVal value As Color)
  1113.         End Set
  1114.     End Property
  1115.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1116.     Overrides Property BackgroundImage() As Image
  1117.         Get
  1118.             Return Nothing
  1119.         End Get
  1120.         Set(ByVal value As Image)
  1121.         End Set
  1122.     End Property
  1123.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1124.     Overrides Property BackgroundImageLayout() As ImageLayout
  1125.         Get
  1126.             Return ImageLayout.None
  1127.         End Get
  1128.         Set(ByVal value As ImageLayout)
  1129.         End Set
  1130.     End Property
  1131.  
  1132.     Overrides Property Text() As String
  1133.         Get
  1134.             Return MyBase.Text
  1135.         End Get
  1136.         Set(ByVal value As String)
  1137.             MyBase.Text = value
  1138.             Invalidate()
  1139.         End Set
  1140.     End Property
  1141.     Overrides Property Font() As Font
  1142.         Get
  1143.             Return MyBase.Font
  1144.         End Get
  1145.         Set(ByVal value As Font)
  1146.             MyBase.Font = value
  1147.             Invalidate()
  1148.         End Set
  1149.     End Property
  1150.  
  1151.     Private _BackColor As Boolean
  1152.     <Category("Misc")> _
  1153.     Overrides Property BackColor() As Color
  1154.         Get
  1155.             Return MyBase.BackColor
  1156.         End Get
  1157.         Set(ByVal value As Color)
  1158.             If Not IsHandleCreated AndAlso value = Color.Transparent Then
  1159.                 _BackColor = True
  1160.                 Return
  1161.             End If
  1162.  
  1163.             MyBase.BackColor = value
  1164.             If Parent IsNot Nothing Then ColorHook()
  1165.         End Set
  1166.     End Property
  1167.  
  1168. #End Region
  1169.  
  1170. #Region " Public Properties "
  1171.  
  1172.     Private _NoRounding As Boolean
  1173.     Property NoRounding() As Boolean
  1174.         Get
  1175.             Return _NoRounding
  1176.         End Get
  1177.         Set(ByVal v As Boolean)
  1178.             _NoRounding = v
  1179.             Invalidate()
  1180.         End Set
  1181.     End Property
  1182.  
  1183.     Private _Image As Image
  1184.     Property Image() As Image
  1185.         Get
  1186.             Return _Image
  1187.         End Get
  1188.         Set(ByVal value As Image)
  1189.             If value Is Nothing Then
  1190.                 _ImageSize = Size.Empty
  1191.             Else
  1192.                 _ImageSize = value.Size
  1193.             End If
  1194.  
  1195.             _Image = value
  1196.             Invalidate()
  1197.         End Set
  1198.     End Property
  1199.  
  1200.     Private _Transparent As Boolean
  1201.     Property Transparent() As Boolean
  1202.         Get
  1203.             Return _Transparent
  1204.         End Get
  1205.         Set(ByVal value As Boolean)
  1206.             _Transparent = value
  1207.             If Not IsHandleCreated Then Return
  1208.  
  1209.             If Not value AndAlso Not BackColor.A = 255 Then
  1210.                 Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  1211.             End If
  1212.  
  1213.             SetStyle(ControlStyles.Opaque, Not value)
  1214.             SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  1215.  
  1216.             If value Then InvalidateBitmap() Else B = Nothing
  1217.             Invalidate()
  1218.         End Set
  1219.     End Property
  1220.  
  1221.     Private Items As New Dictionary(Of String, Color)
  1222.     Property Colors() As Bloom()
  1223.         Get
  1224.             Dim T As New List(Of Bloom)
  1225.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  1226.  
  1227.             While E.MoveNext
  1228.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  1229.             End While
  1230.  
  1231.             Return T.ToArray
  1232.         End Get
  1233.         Set(ByVal value As Bloom())
  1234.             For Each B As Bloom In value
  1235.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  1236.             Next
  1237.  
  1238.             InvalidateCustimization()
  1239.             ColorHook()
  1240.             Invalidate()
  1241.         End Set
  1242.     End Property
  1243.  
  1244.     Private _Customization As String
  1245.     Property Customization() As String
  1246.         Get
  1247.             Return _Customization
  1248.         End Get
  1249.         Set(ByVal value As String)
  1250.             If value = _Customization Then Return
  1251.  
  1252.             Dim Data As Byte()
  1253.             Dim Items As Bloom() = Colors
  1254.  
  1255.             Try
  1256.                 Data = Convert.FromBase64String(value)
  1257.                 For I As Integer = 0 To Items.Length - 1
  1258.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  1259.                 Next
  1260.             Catch
  1261.                 Return
  1262.             End Try
  1263.  
  1264.             _Customization = value
  1265.  
  1266.             Colors = Items
  1267.             ColorHook()
  1268.             Invalidate()
  1269.         End Set
  1270.     End Property
  1271.  
  1272. #End Region
  1273.  
  1274. #Region " Private Properties "
  1275.  
  1276.     Private _ImageSize As Size
  1277.     Protected ReadOnly Property ImageSize() As Size
  1278.         Get
  1279.             Return _ImageSize
  1280.         End Get
  1281.     End Property
  1282.  
  1283.     Private _LockWidth As Integer
  1284.     Protected Property LockWidth() As Integer
  1285.         Get
  1286.             Return _LockWidth
  1287.         End Get
  1288.         Set(ByVal value As Integer)
  1289.             _LockWidth = value
  1290.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  1291.         End Set
  1292.     End Property
  1293.  
  1294.     Private _LockHeight As Integer
  1295.     Protected Property LockHeight() As Integer
  1296.         Get
  1297.             Return _LockHeight
  1298.         End Get
  1299.         Set(ByVal value As Integer)
  1300.             _LockHeight = value
  1301.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  1302.         End Set
  1303.     End Property
  1304.  
  1305. #End Region
  1306.  
  1307.  
  1308. #Region " Property Helpers "
  1309.  
  1310.     Protected Function GetPen(ByVal name As String) As Pen
  1311.         Return New Pen(Items(name))
  1312.     End Function
  1313.     Protected Function GetPen(ByVal name As String, ByVal width As Single) As Pen
  1314.         Return New Pen(Items(name), width)
  1315.     End Function
  1316.  
  1317.     Protected Function GetBrush(ByVal name As String) As SolidBrush
  1318.         Return New SolidBrush(Items(name))
  1319.     End Function
  1320.  
  1321.     Protected Function GetColor(ByVal name As String) As Color
  1322.         Return Items(name)
  1323.     End Function
  1324.  
  1325.     Protected Sub SetColor(ByVal name As String, ByVal value As Color)
  1326.         If Items.ContainsKey(name) Then Items(name) = value Else Items.Add(name, value)
  1327.     End Sub
  1328.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1329.         SetColor(name, Color.FromArgb(r, g, b))
  1330.     End Sub
  1331.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1332.         SetColor(name, Color.FromArgb(a, r, g, b))
  1333.     End Sub
  1334.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal value As Color)
  1335.         SetColor(name, Color.FromArgb(a, value))
  1336.     End Sub
  1337.  
  1338.     Private Sub InvalidateBitmap()
  1339.         If Width = 0 OrElse Height = 0 Then Return
  1340.         B = New Bitmap(Width, Height, PixelFormat.Format32bppPArgb)
  1341.         G = Graphics.FromImage(B)
  1342.     End Sub
  1343.  
  1344.     Private Sub InvalidateCustimization()
  1345.         Dim M As New MemoryStream(Items.Count * 4)
  1346.  
  1347.         For Each B As Bloom In Colors
  1348.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  1349.         Next
  1350.  
  1351.         M.Close()
  1352.         _Customization = Convert.ToBase64String(M.ToArray)
  1353.     End Sub
  1354.  
  1355. #End Region
  1356.  
  1357.  
  1358. #Region " User Hooks "
  1359.  
  1360.     Protected MustOverride Sub ColorHook()
  1361.     Protected MustOverride Sub PaintHook()
  1362.  
  1363.     Protected Overridable Sub OnCreation()
  1364.     End Sub
  1365.  
  1366. #End Region
  1367.  
  1368.  
  1369. #Region " Offset "
  1370.  
  1371.     Private OffsetReturnRectangle As Rectangle
  1372.     Protected Function Offset(ByVal r As Rectangle, ByVal amount As Integer) As Rectangle
  1373.         OffsetReturnRectangle = New Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2))
  1374.         Return OffsetReturnRectangle
  1375.     End Function
  1376.  
  1377.     Private OffsetReturnSize As Size
  1378.     Protected Function Offset(ByVal s As Size, ByVal amount As Integer) As Size
  1379.         OffsetReturnSize = New Size(s.Width + amount, s.Height + amount)
  1380.         Return OffsetReturnSize
  1381.     End Function
  1382.  
  1383.     Private OffsetReturnPoint As Point
  1384.     Protected Function Offset(ByVal p As Point, ByVal amount As Integer) As Point
  1385.         OffsetReturnPoint = New Point(p.X + amount, p.Y + amount)
  1386.         Return OffsetReturnPoint
  1387.     End Function
  1388.  
  1389. #End Region
  1390.  
  1391. #Region " Center "
  1392.  
  1393.     Private CenterReturn As Point
  1394.  
  1395.     Protected Function Center(ByVal p As Rectangle, ByVal c As Rectangle) As Point
  1396.         CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X + c.X, (p.Height \ 2 - c.Height \ 2) + p.Y + c.Y)
  1397.         Return CenterReturn
  1398.     End Function
  1399.     Protected Function Center(ByVal p As Rectangle, ByVal c As Size) As Point
  1400.         CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X, (p.Height \ 2 - c.Height \ 2) + p.Y)
  1401.         Return CenterReturn
  1402.     End Function
  1403.  
  1404.     Protected Function Center(ByVal child As Rectangle) As Point
  1405.         Return Center(Width, Height, child.Width, child.Height)
  1406.     End Function
  1407.     Protected Function Center(ByVal child As Size) As Point
  1408.         Return Center(Width, Height, child.Width, child.Height)
  1409.     End Function
  1410.     Protected Function Center(ByVal childWidth As Integer, ByVal childHeight As Integer) As Point
  1411.         Return Center(Width, Height, childWidth, childHeight)
  1412.     End Function
  1413.  
  1414.     Protected Function Center(ByVal p As Size, ByVal c As Size) As Point
  1415.         Return Center(p.Width, p.Height, c.Width, c.Height)
  1416.     End Function
  1417.  
  1418.     Protected Function Center(ByVal pWidth As Integer, ByVal pHeight As Integer, ByVal cWidth As Integer, ByVal cHeight As Integer) As Point
  1419.         CenterReturn = New Point(pWidth \ 2 - cWidth \ 2, pHeight \ 2 - cHeight \ 2)
  1420.         Return CenterReturn
  1421.     End Function
  1422.  
  1423. #End Region
  1424.  
  1425. #Region " Measure "
  1426.  
  1427.     Private MeasureBitmap As Bitmap
  1428.     Private MeasureGraphics As Graphics 'TODO: Potential issues during multi-threading.
  1429.  
  1430.     Protected Function Measure() As Size
  1431.         Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  1432.     End Function
  1433.     Protected Function Measure(ByVal text As String) As Size
  1434.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  1435.     End Function
  1436.  
  1437. #End Region
  1438.  
  1439.  
  1440. #Region " DrawPixel "
  1441.  
  1442.     Private DrawPixelBrush As SolidBrush
  1443.  
  1444.     Protected Sub DrawPixel(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer)
  1445.         If _Transparent Then
  1446.             B.SetPixel(x, y, c1)
  1447.         Else
  1448.             DrawPixelBrush = New SolidBrush(c1)
  1449.             G.FillRectangle(DrawPixelBrush, x, y, 1, 1)
  1450.         End If
  1451.     End Sub
  1452.  
  1453. #End Region
  1454.  
  1455. #Region " DrawCorners "
  1456.  
  1457.     Private DrawCornersBrush As SolidBrush
  1458.  
  1459.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal offset As Integer)
  1460.         DrawCorners(c1, 0, 0, Width, Height, offset)
  1461.     End Sub
  1462.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle, ByVal offset As Integer)
  1463.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset)
  1464.     End Sub
  1465.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  1466.         DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1467.     End Sub
  1468.  
  1469.     Protected Sub DrawCorners(ByVal c1 As Color)
  1470.         DrawCorners(c1, 0, 0, Width, Height)
  1471.     End Sub
  1472.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  1473.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  1474.     End Sub
  1475.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1476.         If _NoRounding Then Return
  1477.  
  1478.         If _Transparent Then
  1479.             B.SetPixel(x, y, c1)
  1480.             B.SetPixel(x + (width - 1), y, c1)
  1481.             B.SetPixel(x, y + (height - 1), c1)
  1482.             B.SetPixel(x + (width - 1), y + (height - 1), c1)
  1483.         Else
  1484.             DrawCornersBrush = New SolidBrush(c1)
  1485.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  1486.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  1487.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  1488.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  1489.         End If
  1490.     End Sub
  1491.  
  1492. #End Region
  1493.  
  1494. #Region " DrawBorders "
  1495.  
  1496.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  1497.         DrawBorders(p1, 0, 0, Width, Height, offset)
  1498.     End Sub
  1499.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  1500.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  1501.     End Sub
  1502.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  1503.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1504.     End Sub
  1505.  
  1506.     Protected Sub DrawBorders(ByVal p1 As Pen)
  1507.         DrawBorders(p1, 0, 0, Width, Height)
  1508.     End Sub
  1509.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  1510.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  1511.     End Sub
  1512.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1513.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  1514.     End Sub
  1515.  
  1516. #End Region
  1517.  
  1518. #Region " DrawText "
  1519.  
  1520.     Private DrawTextPoint As Point
  1521.     Private DrawTextSize As Size
  1522.  
  1523.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1524.         DrawText(b1, Text, a, x, y)
  1525.     End Sub
  1526.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1527.         If text.Length = 0 Then Return
  1528.  
  1529.         DrawTextSize = Measure(text)
  1530.         DrawTextPoint = Center(DrawTextSize)
  1531.  
  1532.         Select Case a
  1533.             Case HorizontalAlignment.Left
  1534.                 G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y)
  1535.             Case HorizontalAlignment.Center
  1536.                 G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  1537.             Case HorizontalAlignment.Right
  1538.                 G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  1539.         End Select
  1540.     End Sub
  1541.  
  1542.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  1543.         If Text.Length = 0 Then Return
  1544.         G.DrawString(Text, Font, b1, p1)
  1545.     End Sub
  1546.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  1547.         If Text.Length = 0 Then Return
  1548.         G.DrawString(Text, Font, b1, x, y)
  1549.     End Sub
  1550.  
  1551. #End Region
  1552.  
  1553. #Region " DrawImage "
  1554.  
  1555.     Private DrawImagePoint As Point
  1556.  
  1557.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1558.         DrawImage(_Image, a, x, y)
  1559.     End Sub
  1560.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1561.         If image Is Nothing Then Return
  1562.         DrawImagePoint = Center(image.Size)
  1563.  
  1564.         Select Case a
  1565.             Case HorizontalAlignment.Left
  1566.                 G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height)
  1567.             Case HorizontalAlignment.Center
  1568.                 G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height)
  1569.             Case HorizontalAlignment.Right
  1570.                 G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height)
  1571.         End Select
  1572.     End Sub
  1573.  
  1574.     Protected Sub DrawImage(ByVal p1 As Point)
  1575.         DrawImage(_Image, p1.X, p1.Y)
  1576.     End Sub
  1577.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  1578.         DrawImage(_Image, x, y)
  1579.     End Sub
  1580.  
  1581.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  1582.         DrawImage(image, p1.X, p1.Y)
  1583.     End Sub
  1584.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  1585.         If image Is Nothing Then Return
  1586.         G.DrawImage(image, x, y, image.Width, image.Height)
  1587.     End Sub
  1588.  
  1589. #End Region
  1590.  
  1591. #Region " DrawGradient "
  1592.  
  1593.     Private DrawGradientBrush As LinearGradientBrush
  1594.     Private DrawGradientRectangle As Rectangle
  1595.  
  1596.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1597.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1598.         DrawGradient(blend, DrawGradientRectangle)
  1599.     End Sub
  1600.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  1601.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1602.         DrawGradient(blend, DrawGradientRectangle, angle)
  1603.     End Sub
  1604.  
  1605.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle)
  1606.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, 90.0F)
  1607.         DrawGradientBrush.InterpolationColors = blend
  1608.         G.FillRectangle(DrawGradientBrush, r)
  1609.     End Sub
  1610.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  1611.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  1612.         DrawGradientBrush.InterpolationColors = blend
  1613.         G.FillRectangle(DrawGradientBrush, r)
  1614.     End Sub
  1615.  
  1616.  
  1617.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1618.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1619.         DrawGradient(c1, c2, DrawGradientRectangle)
  1620.     End Sub
  1621.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  1622.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1623.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  1624.     End Sub
  1625.  
  1626.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  1627.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, 90.0F)
  1628.         G.FillRectangle(DrawGradientBrush, r)
  1629.     End Sub
  1630.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1631.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  1632.         G.FillRectangle(DrawGradientBrush, r)
  1633.     End Sub
  1634.  
  1635. #End Region
  1636.  
  1637. #Region " DrawRadial "
  1638.  
  1639.     Private DrawRadialPath As GraphicsPath
  1640.     Private DrawRadialBrush1 As PathGradientBrush
  1641.     Private DrawRadialBrush2 As LinearGradientBrush
  1642.     Private DrawRadialRectangle As Rectangle
  1643.  
  1644.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1645.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1646.         DrawRadial(blend, DrawRadialRectangle, width \ 2, height \ 2)
  1647.     End Sub
  1648.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal center As Point)
  1649.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1650.         DrawRadial(blend, DrawRadialRectangle, center.X, center.Y)
  1651.     End Sub
  1652.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal cx As Integer, ByVal cy As Integer)
  1653.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1654.         DrawRadial(blend, DrawRadialRectangle, cx, cy)
  1655.     End Sub
  1656.  
  1657.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle)
  1658.         DrawRadial(blend, r, r.Width \ 2, r.Height \ 2)
  1659.     End Sub
  1660.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal center As Point)
  1661.         DrawRadial(blend, r, center.X, center.Y)
  1662.     End Sub
  1663.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal cx As Integer, ByVal cy As Integer)
  1664.         DrawRadialPath.Reset()
  1665.         DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1)
  1666.  
  1667.         DrawRadialBrush1 = New PathGradientBrush(DrawRadialPath)
  1668.         DrawRadialBrush1.CenterPoint = New Point(r.X + cx, r.Y + cy)
  1669.         DrawRadialBrush1.InterpolationColors = blend
  1670.  
  1671.         If G.SmoothingMode = SmoothingMode.AntiAlias Then
  1672.             G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3)
  1673.         Else
  1674.             G.FillEllipse(DrawRadialBrush1, r)
  1675.         End If
  1676.     End Sub
  1677.  
  1678.  
  1679.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1680.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1681.         DrawRadial(c1, c2, DrawRadialRectangle)
  1682.     End Sub
  1683.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  1684.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1685.         DrawRadial(c1, c2, DrawRadialRectangle, angle)
  1686.     End Sub
  1687.  
  1688.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  1689.         DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, 90.0F)
  1690.         G.FillEllipse(DrawRadialBrush2, r)
  1691.     End Sub
  1692.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1693.         DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, angle)
  1694.         G.FillEllipse(DrawRadialBrush2, r)
  1695.     End Sub
  1696.  
  1697. #End Region
  1698.  
  1699. End Class
  1700. Enum MouseState As Byte
  1701.     None = 0
  1702.     Over = 1
  1703.     Down = 2
  1704.     Block = 3
  1705. End Enum
  1706. Structure Bloom
  1707.  
  1708.     Public _Name As String
  1709.     ReadOnly Property Name() As String
  1710.         Get
  1711.             Return _Name
  1712.         End Get
  1713.     End Property
  1714.  
  1715.     Private _Value As Color
  1716.     Property Value() As Color
  1717.         Get
  1718.             Return _Value
  1719.         End Get
  1720.         Set(ByVal value As Color)
  1721.             _Value = value
  1722.         End Set
  1723.     End Property
  1724.  
  1725.     Sub New(ByVal name As String, ByVal value As Color)
  1726.         _Name = name
  1727.         _Value = value
  1728.     End Sub
  1729. End Structure
  1730. Class GzTheme
  1731.     Inherits ThemeContainer153
  1732.     Sub New()
  1733.         SetColor("tW", 204, 204, 204)
  1734.         SetColor("tLB", 0, 213, 238)
  1735.         SetColor("tDB", 0, 102, 176)
  1736.     End Sub
  1737.     Dim W, LB, DB As Color
  1738.     Protected Overrides Sub ColorHook()
  1739.         TransparencyKey = Color.Bisque
  1740.         Header = 20
  1741.         W = GetColor("tW")
  1742.         LB = GetColor("tLB")
  1743.         DB = GetColor("tDB")
  1744.     End Sub
  1745.  
  1746.     Protected Overrides Sub PaintHook()
  1747.         G.Clear(Color.Gray)
  1748.         DrawBorders(Pens.Gray)
  1749.         G.DrawLine(Pens.Black, 11, 0, 11, Height)
  1750.         DrawGradient(LB, DB, 0, 0, 11, Height)
  1751.         G.DrawLine(Pens.Black, Width - 12, 0, Width - 12, Height)
  1752.         DrawGradient(LB, DB, 12, Height - 12, Width - 24, 12)
  1753.         G.DrawLine(Pens.Black, 11, Height - 12, Width - 12, Height - 12)
  1754.         DrawGradient(LB, DB, Width - 11, 0, 11, Height)
  1755.         DrawGradient(LB, DB, 11, 3, Width - 12, 3)
  1756.         DrawGradient(LB, DB, 0, 0, Width, 20)
  1757.         DrawBorders(Pens.DeepSkyBlue, 0, 0, Width, 21)
  1758.         DrawBorders(Pens.Black, 0, 0, Width, 22)
  1759.         DrawBorders(Pens.Black)
  1760.         DrawText(Brushes.White, HorizontalAlignment.Center, 0, 0)
  1761.     End Sub
  1762. End Class
  1763.  
  1764. Class GzButton
  1765.     Inherits ThemeControl153
  1766.     Sub New()
  1767.         SetColor("tLB", 0, 213, 238)
  1768.         SetColor("tDB", 0, 102, 176)
  1769.         SetColor("tLLB", 0, 223, 248)
  1770.         SetColor("tLDB", 0, 112, 186)
  1771.         SetColor("tDLB", 0, 203, 218)
  1772.         SetColor("tDDB", 0, 92, 166)
  1773.     End Sub
  1774.     Dim LB, DB, LLB, LDB, DLB, DDB As Color
  1775.     Protected Overrides Sub ColorHook()
  1776.         LB = GetColor("tLB")
  1777.         DB = GetColor("tDB")
  1778.         LLB = GetColor("tLLB")
  1779.         LDB = GetColor("tLDB")
  1780.         DLB = GetColor("tDLB")
  1781.         DDB = GetColor("tDDB")
  1782.     End Sub
  1783.  
  1784.     Protected Overrides Sub PaintHook()
  1785.         G.Clear(Color.DodgerBlue)
  1786.  
  1787.         If State = MouseState.None Then
  1788.             DrawGradient(LB, DB, 0, 0, Width, Height, 90S)
  1789.         ElseIf State = MouseState.Over Then
  1790.             DrawGradient(LLB, LDB, 0, 0, Width, Height, 90S)
  1791.         ElseIf State = MouseState.Down Then
  1792.             DrawGradient(DLB, DDB, 0, 0, Width, Height, 90S)
  1793.         End If
  1794.         DrawBorders(Pens.Black, 0)
  1795.         DrawBorders(Pens.DeepSkyBlue, 1)
  1796.         DrawCorners(Color.Gray)
  1797.         DrawCorners(Color.Gray, 1)
  1798.         DrawText(Brushes.White, HorizontalAlignment.Center, 0, 0)
  1799.     End Sub
  1800. End Class
  1801.  
  1802. Class GzProgressBar
  1803.     Inherits ThemeControl153
  1804.     Sub New()
  1805.  
  1806.         SetColor("tW", 204, 204, 204)
  1807.         SetColor("tLB", 0, 213, 238)
  1808.         SetColor("tDB", 0, 102, 176)
  1809.     End Sub
  1810.  
  1811.     Private _Maximum As Integer
  1812.     Public Property Maximum() As Integer
  1813.         Get
  1814.             Select Case _Maximum
  1815.                 Case 0
  1816.                     Return 100
  1817.                 Case Else
  1818.                     Return _Maximum
  1819.             End Select
  1820.         End Get
  1821.         Set(ByVal v As Integer)
  1822.             Select Case v
  1823.                 Case Is < _Value
  1824.                     _Value = v
  1825.             End Select
  1826.             _Maximum = v
  1827.             Invalidate()
  1828.         End Set
  1829.     End Property
  1830.     Private _Value As Integer
  1831.     Public Property Value() As Integer
  1832.         Get
  1833.             Select Case _Value
  1834.                 Case 0
  1835.                     Return 1
  1836.                 Case Else
  1837.                     Return _Value
  1838.             End Select
  1839.         End Get
  1840.         Set(ByVal v As Integer)
  1841.             Select Case v
  1842.                 Case Is > _Maximum
  1843.                     v = _Maximum
  1844.             End Select
  1845.             _Value = v
  1846.             Invalidate()
  1847.         End Set
  1848.     End Property
  1849.  
  1850.     Dim LB, DB, W As Color
  1851.     Private Progress As Integer
  1852.     Dim Blend As New ColorBlend
  1853.     Protected Overrides Sub ColorHook()
  1854.         LB = GetColor("tLB")
  1855.         DB = GetColor("tDB")
  1856.         W = GetColor("tW")
  1857.     End Sub
  1858.  
  1859.     Protected Overrides Sub PaintHook()
  1860.         DrawGradient(Color.White, W, ClientRectangle)
  1861.         DrawBorders(Pens.Black)
  1862.         Dim a As New ColorBlend
  1863.         a.Colors = {LB, DB}
  1864.         a.Positions = {0.0F, 1.0F}
  1865.         G.FillRectangle(Brushes.DimGray, 3, 3, Width - 6, Height - 6)
  1866.         DrawGradient(a, 3, 3, CInt(_Value / _Maximum * Width) - 5, Height - 6, 90S)
  1867.         DrawBorders(Pens.DeepSkyBlue, 4, 4, CInt(_Value / _Maximum * Width) - 5, Height - 8)
  1868.         Dim T As New HatchBrush(HatchStyle.DarkDownwardDiagonal, Color.DeepSkyBlue, Color.Empty)
  1869.         G.FillRectangle(T, New Rectangle(5, 5, CInt((_Value / _Maximum) * Width - 8), Height - 10))
  1870.         DrawBorders(Pens.Black, 3)
  1871.     End Sub
  1872. End Class
  1873.  
  1874. Class GzTopButton
  1875.     Inherits ThemeControl153
  1876.     Sub New()
  1877.         SetColor("tLB", 0, 223, 248)
  1878.         SetColor("tDB", 0, 112, 186)
  1879.         SetColor("tLLB", 0, 233, 255)
  1880.         SetColor("tLDB", 0, 122, 196)
  1881.         SetColor("tDLB", 0, 203, 218)
  1882.         SetColor("tDDB", 0, 92, 166)
  1883.         Size = New Size(20, 14)
  1884.     End Sub
  1885.     Dim LB, DB, LLB, LDB, DLB, DDB As Color
  1886.     Protected Overrides Sub ColorHook()
  1887.         LB = GetColor("tLB")
  1888.         DB = GetColor("tDB")
  1889.         LLB = GetColor("tLLB")
  1890.         LDB = GetColor("tLDB")
  1891.         DLB = GetColor("tDLB")
  1892.         DDB = GetColor("tDDB")
  1893.     End Sub
  1894.  
  1895.     Protected Overrides Sub PaintHook()
  1896.         If State = MouseState.None Then
  1897.             DrawGradient(LB, DB, ClientRectangle)
  1898.         ElseIf State = MouseState.Down Then
  1899.             DrawGradient(DLB, DDB, ClientRectangle)
  1900.         ElseIf State = MouseState.Over Then
  1901.             DrawGradient(LLB, LDB, ClientRectangle)
  1902.         End If
  1903.         DrawBorders(Pens.Black)
  1904.         DrawBorders(Pens.DeepSkyBlue, 1)
  1905.         DrawText(Brushes.White, HorizontalAlignment.Center, -1, 0)
  1906.     End Sub
  1907. End Class
  1908.  
  1909. Class GzCheckBox
  1910.     Inherits ThemeControl153
  1911.     Private _CheckedState As Boolean
  1912.     Public Property CheckedState() As Boolean
  1913.         Get
  1914.             Return _CheckedState
  1915.         End Get
  1916.         Set(ByVal v As Boolean)
  1917.             _CheckedState = v
  1918.             Invalidate()
  1919.         End Set
  1920.     End Property
  1921.  
  1922.     Sub New()
  1923.         SetColor("tLB", 0, 223, 248)
  1924.         SetColor("tDB", 0, 112, 186)
  1925.         SetColor("tW", 204, 204, 204)
  1926.         Size = New Size(18, 18)
  1927.         MinimumSize = New Size(15, 15)
  1928.         MaximumSize = New Size(600, 30)
  1929.     End Sub
  1930.     Dim LB, DB, W As Color
  1931.     Protected Overrides Sub ColorHook()
  1932.         LB = GetColor("tLB")
  1933.         DB = GetColor("tDB")
  1934.         W = GetColor("tW")
  1935.     End Sub
  1936.  
  1937.     Protected Overrides Sub PaintHook()
  1938.         DrawGradient(Color.White, W, ClientRectangle)
  1939.         G.FillRectangle(Brushes.DimGray, 3, 3, Width - 6, Height - 6)
  1940.         DrawBorders(Pens.Black)
  1941.         DrawBorders(Pens.Black, 3)
  1942.         Select Case CheckedState
  1943.             Case True
  1944.                 DrawGradient(LB, DB, 4, 4, 10, 10)
  1945.             Case False
  1946.         End Select
  1947.  
  1948.     End Sub
  1949.     Sub changeCheck() Handles Me.Click
  1950.         Select Case CheckedState
  1951.             Case True
  1952.                 CheckedState = False
  1953.             Case False
  1954.                 CheckedState = True
  1955.         End Select
  1956.     End Sub
  1957. End Class
  1958.  
  1959. Class GzRB1
  1960.     Inherits ThemeControl153
  1961.     Private _CheckedState As Boolean
  1962.     Public Property CheckedState() As Boolean
  1963.         Get
  1964.             Return _CheckedState
  1965.         End Get
  1966.         Set(ByVal v As Boolean)
  1967.             _CheckedState = v
  1968.             Invalidate()
  1969.         End Set
  1970.     End Property
  1971.     Sub New()
  1972.         Size = New Size(90, 17)
  1973.         MinimumSize = New Size(15, 15)
  1974.         MaximumSize = New Size(600, 18)
  1975.         SetColor("tLB", 0, 223, 248)
  1976.         SetColor("tDB", 0, 112, 186)
  1977.         SetColor("dB", 150, 150, 150)
  1978.         SetColor("mB", 200, 200, 200)
  1979.         SetColor("lB", 255, 255, 255)
  1980.     End Sub
  1981.     Dim Bl1, Bl2, Bl3, LB, DB As Color
  1982.     Dim g1 As Pen
  1983.     Dim br1 As SolidBrush
  1984.     Protected Overrides Sub ColorHook()
  1985.         Bl1 = GetColor("dB")
  1986.         Bl2 = GetColor("mB")
  1987.         Bl3 = GetColor("lB")
  1988.         LB = GetColor("tLB")
  1989.         DB = GetColor("tDB")
  1990.         br1 = New SolidBrush(GetColor("mB"))
  1991.     End Sub
  1992.     Protected Overrides Sub PaintHook()
  1993.         G.Clear(Color.Gray)
  1994.         Dim gP As New GraphicsPath
  1995.         gP.AddEllipse(0, 0, 16, 16)
  1996.         Dim gP2 As New GraphicsPath
  1997.         gP2.AddEllipse(0, 0, 16, 16)
  1998.         Dim a2 As New LinearGradientBrush(New Rectangle(0, 0, Width, Height), Bl3, Bl1, 90S)
  1999.         Dim b2 As New Pen(a2)
  2000.         G.FillPath(a2, gP)
  2001.         G.DrawPath(Pens.Black, gP)
  2002.         DrawText(Brushes.DeepSkyBlue, HorizontalAlignment.Left, 18, 0)
  2003.         If State = MouseState.Over Then
  2004.             G.DrawPath(Pens.DeepSkyBlue, gP2)
  2005.         End If
  2006.         Select Case CheckedState
  2007.             Case True
  2008.                 Dim mP As Single() = {0.0F, 1.0F}
  2009.                 Dim mC As Color() = {LB, DB}
  2010.                 Dim mB As New ColorBlend
  2011.                 Dim a3 As New LinearGradientBrush(New Rectangle(0, 0, Width, Height), Bl3, Bl1, 90S)
  2012.                 mB.Colors = mC
  2013.                 mB.Positions = mP
  2014.                 a3.InterpolationColors = mB
  2015.                 G.FillPath(a3, gP)
  2016.                 Dim gP4 As New GraphicsPath
  2017.                 gP4.AddEllipse(0, 0, 16, 16)
  2018.                 G.DrawPath(Pens.Black, gP)
  2019.             Case False
  2020.         End Select
  2021.     End Sub
  2022.     Sub changeCheck() Handles Me.Click
  2023.         Select Case CheckedState
  2024.             Case True
  2025.                 CheckedState = False
  2026.             Case False
  2027.                 CheckedState = True
  2028.         End Select
  2029.     End Sub
  2030. End Class
  2031.  
  2032. Class GzRB2
  2033.     Inherits RadioButton
  2034.     Dim WithEvents radiobtn As RadioButton
  2035.  
  2036.     Sub New()
  2037.         ForeColor = Color.White
  2038.         BackColor = Color.FromArgb(41, 41, 41)
  2039.         Size = New Size(114, 45)
  2040.         MaximumSize = New Size(125, 50)
  2041.     End Sub
  2042.  
  2043.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  2044.         Dim G As Graphics = e.Graphics
  2045.         Dim p As Pen = Pens.DeepSkyBlue
  2046.         Dim Gr As New LinearGradientBrush(New Point(0, 0), New Point(Width, Height), Color.FromArgb(0, 223, 248), Color.Black)
  2047.         Gr.RotateTransform(90S)
  2048.         G.Clear(Color.Gray)
  2049.         Select Case Checked
  2050.             Case True
  2051.                 With G
  2052.                     .SmoothingMode = SmoothingMode.HighQuality
  2053.                     .DrawEllipse(p, 0, 0, 15, 15)
  2054.                     .FillEllipse(Gr, 1, 1, 13, 13)
  2055.                 End With
  2056.             Case False
  2057.                 With G
  2058.                     .SmoothingMode = SmoothingMode.HighQuality
  2059.                 End With
  2060.         End Select
  2061.         G.DrawEllipse(p, 0, 0, 15, 15)
  2062.         G.DrawString(Text.ToString, Font, Brushes.White, New Point(15, 2))
  2063.     End Sub
  2064. End Class
  2065. Class GzGroupBox
  2066.     Inherits ThemeContainer153
  2067.     Sub New()
  2068.         ControlMode = True
  2069.         SetColor("tLB", 0, 223, 248)
  2070.         SetColor("tDB", 0, 112, 186)
  2071.         Size = New Size(150, 105)
  2072.     End Sub
  2073.     Dim lB, dB As Color
  2074.     Protected Overrides Sub ColorHook()
  2075.         lB = GetColor("tLB")
  2076.         dB = GetColor("tDB")
  2077.     End Sub
  2078.  
  2079.     Protected Overrides Sub PaintHook()
  2080.         G.Clear(Color.Gray)
  2081.         G.DrawRectangle(Pens.DeepSkyBlue, 0, 5, Width - 2, Height - 8)
  2082.         DrawGradient(lB, dB, 12, 2, Width - 23, 20)
  2083.         DrawBorders(Pens.DeepSkyBlue, 12, 2, Width - 22, 20)
  2084.         DrawBorders(Pens.Black, 11, 2, Width - 20, 21)
  2085.         DrawText(Brushes.White, HorizontalAlignment.Center, -3, 0)
  2086.     End Sub
  2087. End Class
  2088.  
  2089. Class GzTabControl
  2090.     Inherits TabControl
  2091.  
  2092.     Private LightBlack As Color = Color.FromArgb(24, 24, 24)
  2093.     Private LighterBlack As Color = Color.FromArgb(24, 24, 24)
  2094.     Private DrawGradientBrush, DrawGradientBrush2, DrawGradientBrush3 As LinearGradientBrush
  2095.     Private _ControlBColor As Color
  2096.     Public Property TabTextColor() As Color
  2097.         Get
  2098.             Return _ControlBColor
  2099.         End Get
  2100.         Set(ByVal v As Color)
  2101.             _ControlBColor = v
  2102.             Invalidate()
  2103.         End Set
  2104.     End Property
  2105.  
  2106.     Sub New()
  2107.         MyBase.New()
  2108.         SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  2109.         ControlStyles.ResizeRedraw Or _
  2110.         ControlStyles.UserPaint Or _
  2111.         ControlStyles.DoubleBuffer, True)
  2112.         TabTextColor = Color.White
  2113.     End Sub
  2114.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  2115.         MyBase.OnPaint(e)
  2116.         Dim r2 As New Rectangle(0, 0, Width - 3, 11)
  2117.         Dim r3 As New Rectangle(0, 0, Width - 3, 11)
  2118.         e.Graphics.Clear(Color.Black)
  2119.         Dim ItemBounds As Rectangle
  2120.         Dim TextBrush As New SolidBrush(Color.Empty)
  2121.         Dim TabBrush As New SolidBrush(Color.Lime)
  2122.         e.Graphics.FillRectangle(New SolidBrush(Color.Gray), New Rectangle(1, 1, Width - 2, Height - 2))
  2123.         DrawGradientBrush2 = New LinearGradientBrush(r3, Color.FromArgb(62, Color.White), Color.FromArgb(30, Color.White), 90S)
  2124.         e.Graphics.FillRectangle(DrawGradientBrush2, r2)
  2125.         For TabItemIndex As Integer = 0 To Me.TabCount - 1
  2126.             ItemBounds = Me.GetTabRect(TabItemIndex)
  2127.  
  2128.             If CBool(TabItemIndex And 1) Then
  2129.                 TabBrush.Color = Color.Transparent
  2130.             Else
  2131.                 TabBrush.Color = Color.Transparent
  2132.             End If
  2133.             e.Graphics.FillRectangle(TabBrush, ItemBounds)
  2134.             Dim BorderPen As Pen
  2135.             If TabItemIndex = SelectedIndex Then
  2136.                 BorderPen = New Pen(Color.Transparent, 1)
  2137.             Else
  2138.                 BorderPen = New Pen(Color.Transparent, 1)
  2139.             End If
  2140.             e.Graphics.DrawRectangle(BorderPen, New Rectangle(ItemBounds.Location.X + 3, ItemBounds.Location.Y + 1, ItemBounds.Width - 8, ItemBounds.Height - 4))
  2141.             BorderPen.Dispose()
  2142.             Dim sf As New StringFormat
  2143.             sf.LineAlignment = StringAlignment.Center
  2144.             sf.Alignment = StringAlignment.Center
  2145.             If Me.SelectedIndex = TabItemIndex Then
  2146.  
  2147.                 TextBrush.Color = Color.DeepSkyBlue
  2148.             Else
  2149.                 TextBrush.Color = Color.LightGray
  2150.             End If
  2151.  
  2152.             e.Graphics.DrawString(Me.TabPages(TabItemIndex).Text, Me.Font, TextBrush, RectangleF.op_Implicit(Me.GetTabRect(TabItemIndex)), sf)
  2153.             Try
  2154.                 Me.TabPages(TabItemIndex).BackColor = Color.Gray
  2155.             Catch
  2156.             End Try
  2157.         Next
  2158.         Try
  2159.             For Each tabpg As TabPage In Me.TabPages
  2160.                 tabpg.BorderStyle = BorderStyle.None
  2161.             Next
  2162.         Catch
  2163.         End Try
  2164.         e.Graphics.DrawRectangle(New Pen(New SolidBrush(Color.FromArgb(255, Color.Black))), 2, 0, Width - 5, Height - 3)
  2165.         e.Graphics.DrawRectangle(Pens.DeepSkyBlue, New Rectangle(3, 24, Width - 7, Height - 28))
  2166.         e.Graphics.DrawLine(New Pen(New SolidBrush(Color.FromArgb(255, Color.Black))), 2, 23, Width - 3, 23)
  2167.         e.Graphics.DrawLine(New Pen(New SolidBrush(Color.Gray)), 0, 0, 1, 1)
  2168.         e.Graphics.DrawLine(New Pen(New SolidBrush(Color.Gray)), 2, Height - 2, Width, Height - 2)
  2169.  
  2170.     End Sub
  2171. End Class
Advertisement
Add Comment
Please, Sign In to add comment