Advertisement
Eprouvez

[Release] Classic Theme

Sep 17th, 2011
2,694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 50.19 KB | None | 0 0
  1. Imports System, System.IO, System.Collections.Generic
  2. Imports System.Drawing, System.Drawing.Drawing2D
  3. Imports System.ComponentModel, System.Windows.Forms
  4.  
  5. '------------------
  6. 'Creator: aeonhack
  7. 'Theme By: Eprouvez
  8. 'Site: elitevs.net
  9. 'Created: 8/2/2011
  10. 'Changed: 8/31/2011
  11. 'Version: 1.5.1
  12. 'Released: 9/18/2011
  13. '------------------
  14.  
  15. Enum MouseState As Byte
  16.     None = 0
  17.     Over = 1
  18.     Down = 2
  19.     Block = 3
  20. End Enum
  21.  
  22. Class Bloom
  23.  
  24.     Private _Name As String
  25.     Property Name() As String
  26.         Get
  27.             Return _Name
  28.         End Get
  29.         Set(ByVal value As String)
  30.             _Name = value
  31.         End Set
  32.     End Property
  33.  
  34.     Private _Value As Color
  35.     Property Value() As Color
  36.         Get
  37.             Return _Value
  38.         End Get
  39.         Set(ByVal value As Color)
  40.             _Value = value
  41.         End Set
  42.     End Property
  43.  
  44.     Private _Pen As Pen
  45.     Public Property Pen() As Pen
  46.         Get
  47.             Return _Pen
  48.         End Get
  49.         Set(ByVal value As Pen)
  50.             _Pen = value
  51.         End Set
  52.     End Property
  53.  
  54.     Private _Brush As Brush
  55.     Public Property Brush() As Brush
  56.         Get
  57.             Return _Brush
  58.         End Get
  59.         Set(ByVal value As Brush)
  60.             _Brush = value
  61.         End Set
  62.     End Property
  63.  
  64.     Sub New(ByVal name As String, ByVal value As Color)
  65.         _Name = name
  66.         _Value = value
  67.         _Pen = New Pen(value)
  68.         _Brush = New SolidBrush(value)
  69.     End Sub
  70. End Class
  71.  
  72. MustInherit Class ThemeContainer151
  73.     Inherits ContainerControl
  74.  
  75.     Protected G As Graphics
  76.  
  77.     Sub New()
  78.         SetStyle(DirectCast(139270, ControlStyles), True)
  79.         _ImageSize = Size.Empty
  80.  
  81.         MeasureBitmap = New Bitmap(1, 1)
  82.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  83.  
  84.         Font = New Font("Verdana", 8S)
  85.  
  86.         InvalidateCustimization()
  87.     End Sub
  88.  
  89.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  90.         If Not _LockWidth = 0 Then width = _LockWidth
  91.         If Not _LockHeight = 0 Then height = _LockHeight
  92.         MyBase.SetBoundsCore(x, y, width, height, specified)
  93.     End Sub
  94.  
  95.     Private Header As Rectangle
  96.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  97.         MyBase.OnSizeChanged(e)
  98.         If _Movable AndAlso Not _ControlMode Then Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  99.         Invalidate()
  100.     End Sub
  101.  
  102.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  103.         If Width = 0 OrElse Height = 0 Then Return
  104.         G = e.Graphics
  105.         PaintHook()
  106.     End Sub
  107.  
  108.     Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  109.         InitializeMessages()
  110.         InvalidateCustimization()
  111.         ColorHook()
  112.  
  113.         _IsParentForm = TypeOf Parent Is Form
  114.         If Not _ControlMode Then Dock = DockStyle.Fill
  115.  
  116.         If Not _LockWidth = 0 Then Width = _LockWidth
  117.         If Not _LockHeight = 0 Then Height = _LockHeight
  118.         If Not BackColorWait = Nothing Then BackColor = BackColorWait
  119.  
  120.         If _IsParentForm AndAlso Not _ControlMode Then
  121.             ParentForm.FormBorderStyle = _BorderStyle
  122.             ParentForm.TransparencyKey = _TransparencyKey
  123.         End If
  124.  
  125.         OnCreation()
  126.         MyBase.OnHandleCreated(e)
  127.     End Sub
  128.  
  129.     Protected Overridable Sub OnCreation()
  130.     End Sub
  131.  
  132. #Region " Sizing and Movement "
  133.  
  134.     Protected State As MouseState
  135.     Private Sub SetState(ByVal current As MouseState)
  136.         State = current
  137.         Invalidate()
  138.     End Sub
  139.  
  140.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  141.         If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  142.         MyBase.OnMouseMove(e)
  143.     End Sub
  144.  
  145.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  146.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  147.         MyBase.OnEnabledChanged(e)
  148.     End Sub
  149.  
  150.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  151.         SetState(MouseState.Over)
  152.         MyBase.OnMouseEnter(e)
  153.     End Sub
  154.  
  155.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  156.         SetState(MouseState.Over)
  157.         MyBase.OnMouseUp(e)
  158.     End Sub
  159.  
  160.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  161.         SetState(MouseState.None)
  162.  
  163.         If _Sizable AndAlso Not _ControlMode AndAlso GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  164.             Cursor = Cursors.Default
  165.             Previous = 0
  166.         End If
  167.  
  168.         MyBase.OnMouseLeave(e)
  169.     End Sub
  170.  
  171.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  172.         MyBase.OnMouseDown(e)
  173.  
  174.         If Not e.Button = Windows.Forms.MouseButtons.Left Then Return
  175.         SetState(MouseState.Down)
  176.  
  177.         If _IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode Then Return
  178.  
  179.         If _Movable AndAlso Header.Contains(e.Location) Then
  180.             Capture = False
  181.             DefWndProc(Messages(0))
  182.         ElseIf _Sizable AndAlso Not Previous = 0 Then
  183.             Capture = False
  184.             DefWndProc(Messages(Previous))
  185.         End If
  186.     End Sub
  187.  
  188.     Private GetIndexPoint As Point
  189.     Private B1, B2, B3, B4 As Boolean
  190.     Private Function GetIndex() As Integer
  191.         GetIndexPoint = PointToClient(MousePosition)
  192.         B1 = GetIndexPoint.X < 7
  193.         B2 = GetIndexPoint.X > Width - 7
  194.         B3 = GetIndexPoint.Y < 7
  195.         B4 = GetIndexPoint.Y > Height - 7
  196.  
  197.         If B1 AndAlso B3 Then Return 4
  198.         If B1 AndAlso B4 Then Return 7
  199.         If B2 AndAlso B3 Then Return 5
  200.         If B2 AndAlso B4 Then Return 8
  201.         If B1 Then Return 1
  202.         If B2 Then Return 2
  203.         If B3 Then Return 3
  204.         If B4 Then Return 6
  205.         Return 0
  206.     End Function
  207.  
  208.     Private Current, Previous As Integer
  209.     Private Sub InvalidateMouse()
  210.         Current = GetIndex()
  211.         If Current = Previous Then Return
  212.  
  213.         Previous = Current
  214.         Select Case Previous
  215.             Case 0
  216.                 Cursor = Cursors.Default
  217.             Case 1, 2
  218.                 Cursor = Cursors.SizeWE
  219.             Case 3, 6
  220.                 Cursor = Cursors.SizeNS
  221.             Case 4, 8
  222.                 Cursor = Cursors.SizeNWSE
  223.             Case 5, 7
  224.                 Cursor = Cursors.SizeNESW
  225.         End Select
  226.     End Sub
  227.  
  228.     Private Messages(8) As Message
  229.     Private Sub InitializeMessages()
  230.         Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  231.         For I As Integer = 1 To 8
  232.             Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  233.         Next
  234.     End Sub
  235.  
  236. #End Region
  237.  
  238.  
  239. #Region " Property Overrides "
  240.  
  241.     Private BackColorWait As Color
  242.     Overrides Property BackColor() As Color
  243.         Get
  244.             Return MyBase.BackColor
  245.         End Get
  246.         Set(ByVal value As Color)
  247.             If IsHandleCreated Then
  248.                 If Not _ControlMode Then Parent.BackColor = value
  249.                 MyBase.BackColor = value
  250.             Else
  251.                 BackColorWait = value
  252.             End If
  253.         End Set
  254.     End Property
  255.  
  256.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  257.     Overrides Property ForeColor() As Color
  258.         Get
  259.             Return Color.Empty
  260.         End Get
  261.         Set(ByVal value As Color)
  262.         End Set
  263.     End Property
  264.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  265.     Overrides Property BackgroundImage() As Image
  266.         Get
  267.             Return Nothing
  268.         End Get
  269.         Set(ByVal value As Image)
  270.         End Set
  271.     End Property
  272.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  273.     Overrides Property BackgroundImageLayout() As ImageLayout
  274.         Get
  275.             Return ImageLayout.None
  276.         End Get
  277.         Set(ByVal value As ImageLayout)
  278.         End Set
  279.     End Property
  280.  
  281.     Overrides Property Text() As String
  282.         Get
  283.             Return MyBase.Text
  284.         End Get
  285.         Set(ByVal value As String)
  286.             MyBase.Text = value
  287.             Invalidate()
  288.         End Set
  289.     End Property
  290.  
  291.     Overrides Property Font() As Font
  292.         Get
  293.             Return MyBase.Font
  294.         End Get
  295.         Set(ByVal value As Font)
  296.             MyBase.Font = value
  297.             Invalidate()
  298.         End Set
  299.     End Property
  300.  
  301. #End Region
  302.  
  303. #Region " Properties "
  304.  
  305.     Private _Movable As Boolean = True
  306.     Property Movable() As Boolean
  307.         Get
  308.             Return _Movable
  309.         End Get
  310.         Set(ByVal value As Boolean)
  311.             _Movable = value
  312.         End Set
  313.     End Property
  314.  
  315.     Private _Sizable As Boolean = True
  316.     Property Sizable() As Boolean
  317.         Get
  318.             Return _Sizable
  319.         End Get
  320.         Set(ByVal value As Boolean)
  321.             _Sizable = value
  322.         End Set
  323.     End Property
  324.  
  325.     Private _MoveHeight As Integer = 24
  326.     Protected Property MoveHeight() As Integer
  327.         Get
  328.             Return _MoveHeight
  329.         End Get
  330.         Set(ByVal v As Integer)
  331.             If v < 8 Then Return
  332.             Header = New Rectangle(7, 7, Width - 14, v - 7)
  333.             _MoveHeight = v
  334.             Invalidate()
  335.         End Set
  336.     End Property
  337.  
  338.     Private _ControlMode As Boolean
  339.     Protected Property ControlMode() As Boolean
  340.         Get
  341.             Return _ControlMode
  342.         End Get
  343.         Set(ByVal v As Boolean)
  344.             _ControlMode = v
  345.         End Set
  346.     End Property
  347.  
  348.     Private _TransparencyKey As Color
  349.     Property TransparencyKey() As Color
  350.         Get
  351.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  352.         End Get
  353.         Set(ByVal value As Color)
  354.             If _IsParentForm AndAlso Not _ControlMode Then ParentForm.TransparencyKey = value
  355.             _TransparencyKey = value
  356.         End Set
  357.     End Property
  358.  
  359.     Private _BorderStyle As FormBorderStyle
  360.     Property BorderStyle() As FormBorderStyle
  361.         Get
  362.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  363.         End Get
  364.         Set(ByVal value As FormBorderStyle)
  365.             If _IsParentForm AndAlso Not _ControlMode Then ParentForm.FormBorderStyle = value
  366.             _BorderStyle = value
  367.         End Set
  368.     End Property
  369.  
  370.     Private _NoRounding As Boolean
  371.     Property NoRounding() As Boolean
  372.         Get
  373.             Return _NoRounding
  374.         End Get
  375.         Set(ByVal v As Boolean)
  376.             _NoRounding = v
  377.             Invalidate()
  378.         End Set
  379.     End Property
  380.  
  381.     Private _Image As Image
  382.     Property Image() As Image
  383.         Get
  384.             Return _Image
  385.         End Get
  386.         Set(ByVal value As Image)
  387.             If value Is Nothing Then
  388.                 _ImageSize = Size.Empty
  389.             Else
  390.                 _ImageSize = value.Size
  391.             End If
  392.  
  393.             _Image = value
  394.             Invalidate()
  395.         End Set
  396.     End Property
  397.  
  398.     Private _ImageSize As Size
  399.     Protected ReadOnly Property ImageSize() As Size
  400.         Get
  401.             Return _ImageSize
  402.         End Get
  403.     End Property
  404.  
  405.     Private _IsParentForm As Boolean
  406.     Protected ReadOnly Property IsParentForm As Boolean
  407.         Get
  408.             Return _IsParentForm
  409.         End Get
  410.     End Property
  411.  
  412.     Private _LockWidth As Integer
  413.     Protected Property LockWidth() As Integer
  414.         Get
  415.             Return _LockWidth
  416.         End Get
  417.         Set(ByVal value As Integer)
  418.             _LockWidth = value
  419.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  420.         End Set
  421.     End Property
  422.  
  423.     Private _LockHeight As Integer
  424.     Protected Property LockHeight() As Integer
  425.         Get
  426.             Return _LockHeight
  427.         End Get
  428.         Set(ByVal value As Integer)
  429.             _LockHeight = value
  430.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  431.         End Set
  432.     End Property
  433.  
  434.     Private Items As New Dictionary(Of String, Color)
  435.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  436.     Property Colors() As Bloom()
  437.         Get
  438.             Dim T As New List(Of Bloom)
  439.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  440.  
  441.             While E.MoveNext
  442.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  443.             End While
  444.  
  445.             Return T.ToArray
  446.         End Get
  447.         Set(ByVal value As Bloom())
  448.             For Each B As Bloom In value
  449.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  450.             Next
  451.  
  452.             InvalidateCustimization()
  453.             ColorHook()
  454.             Invalidate()
  455.         End Set
  456.     End Property
  457.  
  458.     Private _Customization As String
  459.     Property Customization() As String
  460.         Get
  461.             Return _Customization
  462.         End Get
  463.         Set(ByVal value As String)
  464.             If value = _Customization Then Return
  465.  
  466.             Dim Data As Byte()
  467.             Dim Items As Bloom() = Colors
  468.  
  469.             Try
  470.                 Data = Convert.FromBase64String(value)
  471.                 For I As Integer = 0 To Items.Length - 1
  472.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  473.                 Next
  474.             Catch
  475.                 Return
  476.             End Try
  477.  
  478.             _Customization = value
  479.  
  480.             Colors = Items
  481.             ColorHook()
  482.             Invalidate()
  483.         End Set
  484.     End Property
  485.  
  486. #End Region
  487.  
  488. #Region " Property Helpers "
  489.  
  490.     Protected Function GetColor(ByVal name As String) As Color
  491.         Return Items(name)
  492.     End Function
  493.  
  494.     Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  495.         If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  496.     End Sub
  497.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  498.         SetColor(name, Color.FromArgb(r, g, b))
  499.     End Sub
  500.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  501.         SetColor(name, Color.FromArgb(a, r, g, b))
  502.     End Sub
  503.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  504.         SetColor(name, color.FromArgb(a, color))
  505.     End Sub
  506.  
  507.     Private Sub InvalidateCustimization()
  508.         Dim M As New MemoryStream(Items.Count * 4)
  509.  
  510.         For Each B As Bloom In Colors
  511.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  512.         Next
  513.  
  514.         M.Close()
  515.         _Customization = Convert.ToBase64String(M.ToArray)
  516.     End Sub
  517.  
  518. #End Region
  519.  
  520.  
  521. #Region " User Hooks "
  522.  
  523.     Protected MustOverride Sub ColorHook()
  524.     Protected MustOverride Sub PaintHook()
  525.  
  526. #End Region
  527.  
  528.  
  529. #Region " Center Overloads "
  530.  
  531.     Private CenterReturn As Point
  532.  
  533.     Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  534.         CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  535.         Return CenterReturn
  536.     End Function
  537.     Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  538.         Return Center(r1, r2.Size)
  539.     End Function
  540.  
  541.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  542.         CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  543.         Return CenterReturn
  544.     End Function
  545.  
  546.     Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  547.         Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  548.     End Function
  549.  
  550.     Protected Function Center(ByVal r1 As Rectangle) As Point
  551.         Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  552.     End Function
  553.     Protected Function Center(ByVal s1 As Size) As Point
  554.         Return Center(Width, Height, s1.Width, s1.Height)
  555.     End Function
  556.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  557.         Return Center(Width, Height, w1, h1)
  558.     End Function
  559.  
  560. #End Region
  561.  
  562. #Region " Measure Overloads "
  563.  
  564.     Private MeasureBitmap As Bitmap
  565.     Private MeasureGraphics As Graphics
  566.  
  567.     Protected Function Measure(ByVal text As String) As Size
  568.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  569.     End Function
  570.     Protected Function Measure() As Size
  571.         Return MeasureGraphics.MeasureString(Text, Font).ToSize
  572.     End Function
  573.  
  574. #End Region
  575.  
  576. #Region " DrawCorners Overloads "
  577.  
  578.     'TODO: Optimize by checking brush color
  579.  
  580.     Private DrawCornersBrush As SolidBrush
  581.  
  582.     Protected Sub DrawCorners(ByVal c1 As Color)
  583.         DrawCorners(c1, 0, 0, Width, Height)
  584.     End Sub
  585.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  586.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  587.     End Sub
  588.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  589.         If _NoRounding Then Return
  590.  
  591.         DrawCornersBrush = New SolidBrush(c1)
  592.         G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  593.         G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  594.         G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  595.         G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  596.     End Sub
  597.  
  598. #End Region
  599.  
  600. #Region " DrawBorders Overloads "
  601.  
  602.     'TODO: Remove triple overload?
  603.  
  604.     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)
  605.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  606.     End Sub
  607.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  608.         DrawBorders(p1, 0, 0, Width, Height, offset)
  609.     End Sub
  610.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  611.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  612.     End Sub
  613.  
  614.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  615.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  616.     End Sub
  617.     Protected Sub DrawBorders(ByVal p1 As Pen)
  618.         DrawBorders(p1, 0, 0, Width, Height)
  619.     End Sub
  620.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  621.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  622.     End Sub
  623.  
  624. #End Region
  625.  
  626. #Region " DrawText Overloads "
  627.  
  628.     'TODO: Remove triple overloads?
  629.  
  630.     Private DrawTextPoint As Point
  631.     Private DrawTextSize As Size
  632.  
  633.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  634.         DrawText(b1, Text, a, x, y)
  635.     End Sub
  636.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  637.         DrawText(b1, Text, p1.X, p1.Y)
  638.     End Sub
  639.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  640.         DrawText(b1, Text, x, y)
  641.     End Sub
  642.  
  643.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  644.         If text.Length = 0 Then Return
  645.         DrawTextSize = Measure(text)
  646.         DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, MoveHeight \ 2 - DrawTextSize.Height \ 2)
  647.  
  648.         Select Case a
  649.             Case HorizontalAlignment.Left
  650.                 DrawText(b1, text, x, DrawTextPoint.Y + y)
  651.             Case HorizontalAlignment.Center
  652.                 DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  653.             Case HorizontalAlignment.Right
  654.                 DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  655.         End Select
  656.     End Sub
  657.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  658.         DrawText(b1, text, p1.X, p1.Y)
  659.     End Sub
  660.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  661.         If text.Length = 0 Then Return
  662.         G.DrawString(text, Font, b1, x, y)
  663.     End Sub
  664.  
  665. #End Region
  666.  
  667. #Region " DrawImage Overloads "
  668.  
  669.     'TODO: Remove triple overloads?
  670.  
  671.     Private DrawImagePoint As Point
  672.  
  673.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  674.         DrawImage(_Image, a, x, y)
  675.     End Sub
  676.     Protected Sub DrawImage(ByVal p1 As Point)
  677.         DrawImage(_Image, p1.X, p1.Y)
  678.     End Sub
  679.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  680.         DrawImage(_Image, x, y)
  681.     End Sub
  682.  
  683.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  684.         If image Is Nothing Then Return
  685.         DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, MoveHeight \ 2 - image.Height \ 2)
  686.  
  687.         Select Case a
  688.             Case HorizontalAlignment.Left
  689.                 DrawImage(image, x, DrawImagePoint.Y + y)
  690.             Case HorizontalAlignment.Center
  691.                 DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  692.             Case HorizontalAlignment.Right
  693.                 DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  694.         End Select
  695.     End Sub
  696.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  697.         DrawImage(image, p1.X, p1.Y)
  698.     End Sub
  699.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  700.         If image Is Nothing Then Return
  701.         G.DrawImage(image, x, y, image.Width, image.Height)
  702.     End Sub
  703.  
  704. #End Region
  705.  
  706. #Region " DrawGradient Overloads "
  707.  
  708.     'TODO: Remove triple overload?
  709.  
  710.     Private DrawGradientBrush As LinearGradientBrush
  711.     Private DrawGradientRectangle As Rectangle
  712.  
  713.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  714.         DrawGradient(blend, x, y, width, height, 90S)
  715.     End Sub
  716.     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)
  717.         DrawGradient(c1, c2, x, y, width, height, 90S)
  718.     End Sub
  719.  
  720.     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)
  721.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  722.         DrawGradient(blend, DrawGradientRectangle, angle)
  723.     End Sub
  724.     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)
  725.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  726.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  727.     End Sub
  728.  
  729.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  730.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  731.         DrawGradientBrush.InterpolationColors = blend
  732.         G.FillRectangle(DrawGradientBrush, r)
  733.     End Sub
  734.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  735.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  736.         G.FillRectangle(DrawGradientBrush, r)
  737.     End Sub
  738.  
  739. #End Region
  740.  
  741. End Class
  742.  
  743. MustInherit Class ThemeControl151
  744.     Inherits Control
  745.  
  746.     Protected G As Graphics, B As Bitmap
  747.  
  748.     Sub New()
  749.         SetStyle(DirectCast(139270, ControlStyles), True)
  750.  
  751.         _ImageSize = Size.Empty
  752.  
  753.         MeasureBitmap = New Bitmap(1, 1)
  754.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  755.  
  756.         Font = New Font("Verdana", 8S)
  757.  
  758.         InvalidateCustimization()
  759.     End Sub
  760.  
  761.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  762.         If Not _LockWidth = 0 Then width = _LockWidth
  763.         If Not _LockHeight = 0 Then height = _LockHeight
  764.         MyBase.SetBoundsCore(x, y, width, height, specified)
  765.     End Sub
  766.  
  767.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  768.         If _Transparent AndAlso Not (Width = 0 OrElse Height = 0) Then
  769.             B = New Bitmap(Width, Height)
  770.             G = Graphics.FromImage(B)
  771.         End If
  772.  
  773.         Invalidate()
  774.         MyBase.OnSizeChanged(e)
  775.     End Sub
  776.  
  777.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  778.         If Width = 0 OrElse Height = 0 Then Return
  779.  
  780.         If _Transparent Then
  781.             PaintHook()
  782.             e.Graphics.DrawImage(B, 0, 0)
  783.         Else
  784.             G = e.Graphics
  785.             PaintHook()
  786.         End If
  787.     End Sub
  788.  
  789.     Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  790.         InvalidateCustimization()
  791.         ColorHook()
  792.  
  793.         If Not _LockWidth = 0 Then Width = _LockWidth
  794.         If Not _LockHeight = 0 Then Height = _LockHeight
  795.         If Not BackColorWait = Nothing Then BackColor = BackColorWait
  796.  
  797.         OnCreation()
  798.         MyBase.OnHandleCreated(e)
  799.     End Sub
  800.  
  801.     Protected Overridable Sub OnCreation()
  802.     End Sub
  803.  
  804. #Region " State Handling "
  805.  
  806.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  807.         SetState(MouseState.Over)
  808.         MyBase.OnMouseEnter(e)
  809.     End Sub
  810.  
  811.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  812.         SetState(MouseState.Over)
  813.         MyBase.OnMouseUp(e)
  814.     End Sub
  815.  
  816.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  817.         If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  818.         MyBase.OnMouseDown(e)
  819.     End Sub
  820.  
  821.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  822.         SetState(MouseState.None)
  823.         MyBase.OnMouseLeave(e)
  824.     End Sub
  825.  
  826.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  827.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  828.         MyBase.OnEnabledChanged(e)
  829.     End Sub
  830.  
  831.     Protected State As MouseState
  832.     Private Sub SetState(ByVal current As MouseState)
  833.         State = current
  834.         Invalidate()
  835.     End Sub
  836.  
  837. #End Region
  838.  
  839.  
  840. #Region " Property Overrides "
  841.  
  842.     Private BackColorWait As Color
  843.     Overrides Property BackColor() As Color
  844.         Get
  845.             Return MyBase.BackColor
  846.         End Get
  847.         Set(ByVal value As Color)
  848.             If IsHandleCreated Then
  849.                 MyBase.BackColor = value
  850.             Else
  851.                 BackColorWait = value
  852.             End If
  853.         End Set
  854.     End Property
  855.  
  856.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  857.     Overrides Property ForeColor() As Color
  858.         Get
  859.             Return Color.Empty
  860.         End Get
  861.         Set(ByVal value As Color)
  862.         End Set
  863.     End Property
  864.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  865.     Overrides Property BackgroundImage() As Image
  866.         Get
  867.             Return Nothing
  868.         End Get
  869.         Set(ByVal value As Image)
  870.         End Set
  871.     End Property
  872.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  873.     Overrides Property BackgroundImageLayout() As ImageLayout
  874.         Get
  875.             Return ImageLayout.None
  876.         End Get
  877.         Set(ByVal value As ImageLayout)
  878.         End Set
  879.     End Property
  880.  
  881.     Overrides Property Text() As String
  882.         Get
  883.             Return MyBase.Text
  884.         End Get
  885.         Set(ByVal value As String)
  886.             MyBase.Text = value
  887.             Invalidate()
  888.         End Set
  889.     End Property
  890.  
  891.     Overrides Property Font() As Font
  892.         Get
  893.             Return MyBase.Font
  894.         End Get
  895.         Set(ByVal value As Font)
  896.             MyBase.Font = value
  897.             Invalidate()
  898.         End Set
  899.     End Property
  900.  
  901. #End Region
  902.  
  903. #Region " Properties "
  904.  
  905.     Private _NoRounding As Boolean
  906.     Property NoRounding() As Boolean
  907.         Get
  908.             Return _NoRounding
  909.         End Get
  910.         Set(ByVal v As Boolean)
  911.             _NoRounding = v
  912.             Invalidate()
  913.         End Set
  914.     End Property
  915.  
  916.     Private _Image As Image
  917.     Property Image() As Image
  918.         Get
  919.             Return _Image
  920.         End Get
  921.         Set(ByVal value As Image)
  922.             If value Is Nothing Then
  923.                 _ImageSize = Size.Empty
  924.             Else
  925.                 _ImageSize = value.Size
  926.             End If
  927.  
  928.             _Image = value
  929.             Invalidate()
  930.         End Set
  931.     End Property
  932.  
  933.     Private _ImageSize As Size
  934.     Protected ReadOnly Property ImageSize() As Size
  935.         Get
  936.             Return _ImageSize
  937.         End Get
  938.     End Property
  939.  
  940.     Private _LockWidth As Integer
  941.     Protected Property LockWidth() As Integer
  942.         Get
  943.             Return _LockWidth
  944.         End Get
  945.         Set(ByVal value As Integer)
  946.             _LockWidth = value
  947.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  948.         End Set
  949.     End Property
  950.  
  951.     Private _LockHeight As Integer
  952.     Protected Property LockHeight() As Integer
  953.         Get
  954.             Return _LockHeight
  955.         End Get
  956.         Set(ByVal value As Integer)
  957.             _LockHeight = value
  958.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  959.         End Set
  960.     End Property
  961.  
  962.     Private _Transparent As Boolean
  963.     Property Transparent() As Boolean
  964.         Get
  965.             Return _Transparent
  966.         End Get
  967.         Set(ByVal value As Boolean)
  968.             If Not value AndAlso Not BackColor.A = 255 Then
  969.                 Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  970.             End If
  971.  
  972.             SetStyle(ControlStyles.Opaque, Not value)
  973.             SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  974.  
  975.             If value Then InvalidateBitmap() Else B = Nothing
  976.  
  977.             _Transparent = value
  978.             Invalidate()
  979.         End Set
  980.     End Property
  981.  
  982.     Private Items As New Dictionary(Of String, Color)
  983.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  984.     Property Colors() As Bloom()
  985.         Get
  986.             Dim T As New List(Of Bloom)
  987.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  988.  
  989.             While E.MoveNext
  990.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  991.             End While
  992.  
  993.             Return T.ToArray
  994.         End Get
  995.         Set(ByVal value As Bloom())
  996.             For Each B As Bloom In value
  997.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  998.             Next
  999.  
  1000.             InvalidateCustimization()
  1001.             ColorHook()
  1002.             Invalidate()
  1003.         End Set
  1004.     End Property
  1005.  
  1006.     Private _Customization As String
  1007.     Property Customization() As String
  1008.         Get
  1009.             Return _Customization
  1010.         End Get
  1011.         Set(ByVal value As String)
  1012.             If value = _Customization Then Return
  1013.  
  1014.             Dim Data As Byte()
  1015.             Dim Items As Bloom() = Colors
  1016.  
  1017.             Try
  1018.                 Data = Convert.FromBase64String(value)
  1019.                 For I As Integer = 0 To Items.Length - 1
  1020.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  1021.                 Next
  1022.             Catch
  1023.                 Return
  1024.             End Try
  1025.  
  1026.             _Customization = value
  1027.  
  1028.             Colors = Items
  1029.             ColorHook()
  1030.             Invalidate()
  1031.         End Set
  1032.     End Property
  1033.  
  1034. #End Region
  1035.  
  1036. #Region " Property Helpers "
  1037.  
  1038.     Private Sub InvalidateBitmap()
  1039.         If Width = 0 OrElse Height = 0 Then Return
  1040.         B = New Bitmap(Width, Height)
  1041.         G = Graphics.FromImage(B)
  1042.     End Sub
  1043.  
  1044.     Protected Function GetColor(ByVal name As String) As Color
  1045.         Return Items(name)
  1046.     End Function
  1047.  
  1048.     Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  1049.         If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  1050.     End Sub
  1051.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1052.         SetColor(name, Color.FromArgb(r, g, b))
  1053.     End Sub
  1054.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1055.         SetColor(name, Color.FromArgb(a, r, g, b))
  1056.     End Sub
  1057.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  1058.         SetColor(name, color.FromArgb(a, color))
  1059.     End Sub
  1060.  
  1061.     Private Sub InvalidateCustimization()
  1062.         Dim M As New MemoryStream(Items.Count * 4)
  1063.  
  1064.         For Each B As Bloom In Colors
  1065.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  1066.         Next
  1067.  
  1068.         M.Close()
  1069.         _Customization = Convert.ToBase64String(M.ToArray)
  1070.     End Sub
  1071.  
  1072. #End Region
  1073.  
  1074.  
  1075. #Region " User Hooks "
  1076.  
  1077.     Protected MustOverride Sub ColorHook()
  1078.     Protected MustOverride Sub PaintHook()
  1079.  
  1080. #End Region
  1081.  
  1082.  
  1083. #Region " Center Overloads "
  1084.  
  1085.     Private CenterReturn As Point
  1086.  
  1087.     Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  1088.         CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  1089.         Return CenterReturn
  1090.     End Function
  1091.     Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  1092.         Return Center(r1, r2.Size)
  1093.     End Function
  1094.  
  1095.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  1096.         CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  1097.         Return CenterReturn
  1098.     End Function
  1099.  
  1100.     Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  1101.         Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  1102.     End Function
  1103.  
  1104.     Protected Function Center(ByVal r1 As Rectangle) As Point
  1105.         Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  1106.     End Function
  1107.     Protected Function Center(ByVal s1 As Size) As Point
  1108.         Return Center(Width, Height, s1.Width, s1.Height)
  1109.     End Function
  1110.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  1111.         Return Center(Width, Height, w1, h1)
  1112.     End Function
  1113.  
  1114. #End Region
  1115.  
  1116. #Region " Measure Overloads "
  1117.  
  1118.     Private MeasureBitmap As Bitmap
  1119.     Private MeasureGraphics As Graphics
  1120.  
  1121.     Protected Function Measure(ByVal text As String) As Size
  1122.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  1123.     End Function
  1124.     Protected Function Measure() As Size
  1125.         Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  1126.     End Function
  1127.  
  1128. #End Region
  1129.  
  1130. #Region " DrawCorners Overloads "
  1131.  
  1132.     'TODO: Optimize by checking brush color
  1133.  
  1134.     Private DrawCornersBrush As SolidBrush
  1135.  
  1136.     Protected Sub DrawCorners(ByVal c1 As Color)
  1137.         DrawCorners(c1, 0, 0, Width, Height)
  1138.     End Sub
  1139.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  1140.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  1141.     End Sub
  1142.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1143.         If _NoRounding Then Return
  1144.  
  1145.         If _Transparent Then
  1146.             B.SetPixel(x, y, c1)
  1147.             B.SetPixel(x + (width - 1), y, c1)
  1148.             B.SetPixel(x, y + (height - 1), c1)
  1149.             B.SetPixel(x + (width - 1), y + (height - 1), c1)
  1150.         Else
  1151.             DrawCornersBrush = New SolidBrush(c1)
  1152.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  1153.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  1154.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  1155.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  1156.         End If
  1157.     End Sub
  1158.  
  1159. #End Region
  1160.  
  1161. #Region " DrawBorders Overloads "
  1162.  
  1163.     'TODO: Remove triple overload?
  1164.  
  1165.     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)
  1166.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1167.     End Sub
  1168.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  1169.         DrawBorders(p1, 0, 0, Width, Height, offset)
  1170.     End Sub
  1171.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  1172.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  1173.     End Sub
  1174.  
  1175.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1176.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  1177.     End Sub
  1178.     Protected Sub DrawBorders(ByVal p1 As Pen)
  1179.         DrawBorders(p1, 0, 0, Width, Height)
  1180.     End Sub
  1181.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  1182.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  1183.     End Sub
  1184.  
  1185. #End Region
  1186.  
  1187. #Region " DrawText Overloads "
  1188.  
  1189.     'TODO: Remove triple overloads?
  1190.  
  1191.     Private DrawTextPoint As Point
  1192.     Private DrawTextSize As Size
  1193.  
  1194.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1195.         DrawText(b1, Text, a, x, y)
  1196.     End Sub
  1197.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  1198.         DrawText(b1, Text, p1.X, p1.Y)
  1199.     End Sub
  1200.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  1201.         DrawText(b1, Text, x, y)
  1202.     End Sub
  1203.  
  1204.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1205.         If text.Length = 0 Then Return
  1206.         DrawTextSize = Measure(text)
  1207.         DrawTextPoint = Center(DrawTextSize)
  1208.  
  1209.         Select Case a
  1210.             Case HorizontalAlignment.Left
  1211.                 DrawText(b1, text, x, DrawTextPoint.Y + y)
  1212.             Case HorizontalAlignment.Center
  1213.                 DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  1214.             Case HorizontalAlignment.Right
  1215.                 DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  1216.         End Select
  1217.     End Sub
  1218.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  1219.         DrawText(b1, text, p1.X, p1.Y)
  1220.     End Sub
  1221.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  1222.         If text.Length = 0 Then Return
  1223.         G.DrawString(text, Font, b1, x, y)
  1224.     End Sub
  1225.  
  1226. #End Region
  1227.  
  1228. #Region " DrawImage Overloads "
  1229.  
  1230.     'TODO: Remove triple overloads?
  1231.  
  1232.     Private DrawImagePoint As Point
  1233.  
  1234.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1235.         DrawImage(_Image, a, x, y)
  1236.     End Sub
  1237.     Protected Sub DrawImage(ByVal p1 As Point)
  1238.         DrawImage(_Image, p1.X, p1.Y)
  1239.     End Sub
  1240.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  1241.         DrawImage(_Image, x, y)
  1242.     End Sub
  1243.  
  1244.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1245.         If image Is Nothing Then Return
  1246.         DrawImagePoint = Center(image.Size)
  1247.  
  1248.         Select Case a
  1249.             Case HorizontalAlignment.Left
  1250.                 DrawImage(image, x, DrawImagePoint.Y + y)
  1251.             Case HorizontalAlignment.Center
  1252.                 DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  1253.             Case HorizontalAlignment.Right
  1254.                 DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  1255.         End Select
  1256.     End Sub
  1257.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  1258.         DrawImage(image, p1.X, p1.Y)
  1259.     End Sub
  1260.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  1261.         If image Is Nothing Then Return
  1262.         G.DrawImage(image, x, y, image.Width, image.Height)
  1263.     End Sub
  1264.  
  1265. #End Region
  1266.  
  1267. #Region " DrawGradient Overloads "
  1268.  
  1269.     'TODO: Remove triple overload?
  1270.  
  1271.     Private DrawGradientBrush As LinearGradientBrush
  1272.     Private DrawGradientRectangle As Rectangle
  1273.  
  1274.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1275.         DrawGradient(blend, x, y, width, height, 90S)
  1276.     End Sub
  1277.     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)
  1278.         DrawGradient(c1, c2, x, y, width, height, 90S)
  1279.     End Sub
  1280.  
  1281.     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)
  1282.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1283.         DrawGradient(blend, DrawGradientRectangle, angle)
  1284.     End Sub
  1285.     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)
  1286.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1287.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  1288.     End Sub
  1289.  
  1290.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  1291.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  1292.         DrawGradientBrush.InterpolationColors = blend
  1293.         G.FillRectangle(DrawGradientBrush, r)
  1294.     End Sub
  1295.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1296.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  1297.         G.FillRectangle(DrawGradientBrush, r)
  1298.     End Sub
  1299.  
  1300. #End Region
  1301.  
  1302. End Class
  1303.  
  1304. MustInherit Class ThemeContainerControl
  1305.     Inherits ContainerControl
  1306.  
  1307. #Region " Initialization "
  1308.  
  1309.     Protected G As Graphics, B As Bitmap
  1310.     Sub New()
  1311.         SetStyle(DirectCast(139270, ControlStyles), True)
  1312.         B = New Bitmap(1, 1)
  1313.         G = Graphics.FromImage(B)
  1314.     End Sub
  1315.  
  1316.     Sub AllowTransparent()
  1317.         SetStyle(ControlStyles.Opaque, False)
  1318.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  1319.     End Sub
  1320.  
  1321. #End Region
  1322.  
  1323. #Region " Convienence "
  1324.  
  1325.     Protected MustOverride Sub PaintHook()
  1326.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  1327.         If Width = 0 OrElse Height = 0 Then Return
  1328.         G = e.Graphics
  1329.         PaintHook()
  1330.     End Sub
  1331.  
  1332.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  1333.         If Not Width = 0 AndAlso Not Height = 0 Then
  1334.             B = New Bitmap(Width, Height)
  1335.             G = Graphics.FromImage(B)
  1336.             Invalidate()
  1337.         End If
  1338.         MyBase.OnSizeChanged(e)
  1339.     End Sub
  1340.  
  1341.     Private _NoRounding As Boolean
  1342.     Property NoRounding() As Boolean
  1343.         Get
  1344.             Return _NoRounding
  1345.         End Get
  1346.         Set(ByVal v As Boolean)
  1347.             _NoRounding = v
  1348.             Invalidate()
  1349.         End Set
  1350.     End Property
  1351.  
  1352.     Private _Rectangle As Rectangle
  1353.     Private _Gradient As LinearGradientBrush
  1354.  
  1355.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  1356.         If _NoRounding Then Return
  1357.         B.SetPixel(rect.X, rect.Y, c)
  1358.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  1359.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  1360.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  1361.     End Sub
  1362.  
  1363.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  1364.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  1365.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  1366.     End Sub
  1367.  
  1368.     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)
  1369.         _Rectangle = New Rectangle(x, y, width, height)
  1370.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  1371.         G.FillRectangle(_Gradient, _Rectangle)
  1372.     End Sub
  1373. #End Region
  1374.  
  1375. End Class
  1376.  
  1377. Class Classic
  1378.     Inherits ThemeContainer151
  1379.     Private Bloom As Bloom()
  1380.     Private R1 As Rectangle
  1381.     Private L1 As LinearGradientBrush
  1382.     Private H As HatchBrush
  1383.     Sub New()
  1384.         Bloom = {New Bloom("Border", Color.Black), New Bloom("Highlight Border", Color.FromArgb(87, 87, 87)), _
  1385.                  New Bloom("BackColor", Color.FromArgb(51, 51, 51)), New Bloom("Text Color", Color.FromArgb(128, Color.White)), _
  1386.                  New Bloom("Background", Color.FromArgb(73, 73, 73)), New Bloom("Grid Color", Color.FromArgb(128, 31, 31, 31)), _
  1387.                  New Bloom("Gradient #1", Color.FromArgb(128, Color.Black)), New Bloom("Highlight", Color.FromArgb(26, Color.White)), _
  1388.                  New Bloom("Shadow", Color.FromArgb(10, Color.Black)), New Bloom("Trasparency", Color.Fuchsia) With {.Pen = New Pen(.Value, 2)}}
  1389.         TransparencyKey = Color.Fuchsia
  1390.         MoveHeight = 22
  1391.         Font = New Font("Verdana", 7.0F)
  1392.     End Sub
  1393.     Protected Overrides Sub ColorHook()
  1394.  
  1395.     End Sub
  1396.  
  1397.     Protected Overrides Sub PaintHook()
  1398.         G.Clear(Bloom(0).Value)
  1399.         DrawBorders(Bloom(1).Pen, 1, 1, Width - 2, Height - 2)
  1400.         G.FillRectangle(Bloom(2).Brush, 2, 2, Width - 4, 18)
  1401.         G.FillRectangle(Bloom(2).Brush, 2, Height - 20, Width - 4, 18)
  1402.         G.DrawLine(Bloom(1).Pen, 2, 21, Width - 2, 21)
  1403.         G.FillRectangle(Bloom(4).Brush, 2, 22, Width - 4, Height - 44)
  1404.         G.DrawLine(Bloom(1).Pen, 2, Height - 21, Width - 2, Height - 21)
  1405.  
  1406.         H = New HatchBrush(HatchStyle.SmallCheckerBoard, Bloom(5).Value, Color.Transparent)
  1407.         R1 = New Rectangle(2, 2, Width - 4, Height)
  1408.         L1 = New LinearGradientBrush(R1, Color.Transparent, Bloom(6).Value, 270S)
  1409.         G.FillRectangle(L1, ClientRectangle)
  1410.  
  1411.         G.FillRectangle(H, 2, 22, Width - 4, Height - 44)
  1412.  
  1413.         G.FillRectangle(Bloom(7).Brush, 0, 0, Width, 5)
  1414.  
  1415.         G.FillRectangle(Bloom(8).Brush, 0, 4, Width, Height - 10)
  1416.  
  1417.         If _Round Then
  1418.             G.DrawArc(Bloom(9).Pen, -1, -1, 9, 9, 180, 90)
  1419.             G.DrawArc(Bloom(9).Pen, Width - 9, -1, 9, 9, 270, 90)
  1420.  
  1421.             G.DrawArc(Bloom(9).Pen, Width - 9, Height - 9, 9, 9, 360, 90)
  1422.             G.DrawArc(Bloom(9).Pen, -1, Height - 9, 9, 9, 90, 90)
  1423.  
  1424.             G.DrawArc(Bloom(0).Pen, 0, 0, 9, 9, 180, 90)
  1425.             G.DrawArc(Bloom(0).Pen, Width - 10, 0, 9, 9, 270, 90)
  1426.  
  1427.             G.DrawArc(Bloom(0).Pen, Width - 10, Height - 10, 9, 9, 360, 90)
  1428.             G.DrawArc(Bloom(0).Pen, 0, Height - 10, 9, 9, 90, 90)
  1429.         Else
  1430.             DrawCorners(Color.Fuchsia)
  1431.         End If
  1432.  
  1433.         DrawText(Bloom(3).Brush, 5, 5)
  1434.     End Sub
  1435.  
  1436.     Private _Round As Boolean = False
  1437.     Public Property NewProperty() As Boolean
  1438.         Get
  1439.             Return _Round
  1440.         End Get
  1441.         Set(ByVal value As Boolean)
  1442.             _Round = value
  1443.             Invalidate()
  1444.         End Set
  1445.     End Property
  1446.  
  1447. End Class
  1448. Class ClassicButton
  1449.     Inherits ThemeControl151
  1450.     Private Bloom As Bloom()
  1451.     Private L1 As LinearGradientBrush
  1452.     Private R1 As Rectangle
  1453.     Sub New()
  1454.         Bloom = {New Bloom("Border", Color.Black), New Bloom("Highlight", Color.FromArgb(35, 35, 35)), _
  1455.                  New Bloom("Background", Color.FromArgb(24, 24, 24)), New Bloom("Shadow", Color.FromArgb(100, Color.Black)), _
  1456.                  New Bloom("Text Color", Color.FromArgb(128, Color.White))}
  1457.         Font = New Font("Verdana", 7.0F)
  1458.         Size = New Size(97, 23)
  1459.     End Sub
  1460.  
  1461.     Protected Overrides Sub ColorHook()
  1462.  
  1463.     End Sub
  1464.  
  1465.     Protected Overrides Sub PaintHook()
  1466.         G.FillRectangle(Bloom(2).Brush, ClientRectangle)
  1467.         DrawBorders(Bloom(0).Pen, ClientRectangle)
  1468.         DrawBorders(Bloom(1).Pen, 1, 1, Width - 2, Height - 2)
  1469.         R1 = New Rectangle(2, 2, Width - 4, Height - 4)
  1470.         Select Case State
  1471.             Case MouseState.Over
  1472.                 L1 = New LinearGradientBrush(ClientRectangle, Color.FromArgb(100, 0, 156, 255), Color.Transparent, 270S)
  1473.                 G.FillRectangle(L1, R1)
  1474.                 G.FillRectangle(Bloom(3).Brush, 1, 7, Width - 2, Height - 7)
  1475.             Case MouseState.Down
  1476.                 L1 = New LinearGradientBrush(ClientRectangle, Color.FromArgb(50, 0, 156, 255), Color.Transparent, 90S)
  1477.                 G.FillRectangle(L1, R1)
  1478.                 G.FillRectangle(Bloom(3).Brush, 1, 7, Width - 2, Height - 7)
  1479.             Case MouseState.None
  1480.                 G.FillRectangle(Bloom(3).Brush, 1, 8, Width - 2, Height - 8)
  1481.         End Select
  1482.         DrawText(Bloom(4).Brush, HorizontalAlignment.Center, 0, 0)
  1483.     End Sub
  1484. End Class
  1485. Class ClassicPanel
  1486.     Inherits ThemeContainerControl
  1487.     Private Bloom As Bloom()
  1488.     Private L1, L2, L3 As LinearGradientBrush
  1489.     Private R1, R2, R3 As Rectangle
  1490.     Sub New()
  1491.         Bloom = {New Bloom("Border", Color.FromArgb(87, 87, 87)), New Bloom("Border #2", Color.Black), _
  1492.                  New Bloom("Color #1", Color.FromArgb(49, 49, 49)), New Bloom("Color #2", Color.FromArgb(35, 35, 35)), _
  1493.                  New Bloom("Shadow", Color.FromArgb(31, 31, 31))}
  1494.     End Sub
  1495.  
  1496.     Protected Overrides Sub PaintHook()
  1497.         G.Clear(Color.White)
  1498.         DrawBorders(Bloom(0).Pen, Bloom(1).Pen, ClientRectangle)
  1499.         DrawCorners(BackColor, ClientRectangle)
  1500.         R1 = New Rectangle(2, 2, Width - 4, Height - 4)
  1501.         R2 = New Rectangle(2, 2, 15, Height - 4)
  1502.         R3 = New Rectangle(2, 2, Width - 4, 15)
  1503.         L1 = New LinearGradientBrush(R1, Bloom(2).Value, Bloom(3).Value, 90S)
  1504.         L2 = New LinearGradientBrush(R2, Bloom(4).Value, Color.Transparent, 0S)
  1505.         L3 = New LinearGradientBrush(R3, Bloom(4).Value, Color.Transparent, 90S)
  1506.         G.FillRectangle(L1, R1)
  1507.         G.FillRectangle(L2, R2)
  1508.         G.FillRectangle(L3, R3)
  1509.     End Sub
  1510. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement