Advertisement
benito

Untitled

Sep 7th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 23.82 KB | None | 0 0
  1. #Region "Imports"
  2. Imports System.Drawing.Drawing2D
  3. Imports System.ComponentModel
  4. Imports System.Runtime.InteropServices
  5. #End Region
  6. MustInherit Class Theme
  7.     Inherits ContainerControl
  8.  
  9. #Region " Initialization "
  10.  
  11.     Protected G As Graphics
  12.     Sub New()
  13.         SetStyle(DirectCast(139270, ControlStyles), True)
  14.     End Sub
  15.  
  16.     Private ParentIsForm As Boolean
  17.     Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  18.         Dock = DockStyle.Fill
  19.         ParentIsForm = TypeOf Parent Is Form
  20.         If ParentIsForm Then
  21.             If Not _TransparencyKey = Color.Empty Then ParentForm.TransparencyKey = _TransparencyKey
  22.             ParentForm.FormBorderStyle = FormBorderStyle.None
  23.         End If
  24.         MyBase.OnHandleCreated(e)
  25.     End Sub
  26.  
  27.     Overrides Property Text As String
  28.         Get
  29.             Return MyBase.Text
  30.         End Get
  31.         Set(ByVal v As String)
  32.             MyBase.Text = v
  33.             Invalidate()
  34.         End Set
  35.     End Property
  36. #End Region
  37.  
  38. #Region " Sizing and Movement "
  39.  
  40.     Private _Resizable As Boolean = True
  41.     Property Resizable() As Boolean
  42.         Get
  43.             Return _Resizable
  44.         End Get
  45.         Set(ByVal value As Boolean)
  46.             _Resizable = value
  47.         End Set
  48.     End Property
  49.  
  50.     Private _MoveHeight As Integer = 24
  51.     Property MoveHeight() As Integer
  52.         Get
  53.             Return _MoveHeight
  54.         End Get
  55.         Set(ByVal v As Integer)
  56.             _MoveHeight = v
  57.             Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  58.         End Set
  59.     End Property
  60.  
  61.     Private Flag As IntPtr
  62.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  63.         If Not e.Button = MouseButtons.Left Then Return
  64.         If ParentIsForm Then If ParentForm.WindowState = FormWindowState.Maximized Then Return
  65.  
  66.         If Header.Contains(e.Location) Then
  67.             Flag = New IntPtr(2)
  68.         ElseIf Current.Position = 0 Or Not _Resizable Then
  69.             Return
  70.         Else
  71.             Flag = New IntPtr(Current.Position)
  72.         End If
  73.  
  74.         Capture = False
  75.         DefWndProc(Message.Create(Parent.Handle, 161, Flag, Nothing))
  76.  
  77.         MyBase.OnMouseDown(e)
  78.     End Sub
  79.  
  80.     Private Structure Pointer
  81.         ReadOnly Cursor As Cursor, Position As Byte
  82.         Sub New(ByVal c As Cursor, ByVal p As Byte)
  83.             Cursor = c
  84.             Position = p
  85.         End Sub
  86.     End Structure
  87.  
  88.     Private F1, F2, F3, F4 As Boolean, PTC As Point
  89.     Private Function GetPointer() As Pointer
  90.         PTC = PointToClient(MousePosition)
  91.         F1 = PTC.X < 7
  92.         F2 = PTC.X > Width - 7
  93.         F3 = PTC.Y < 7
  94.         F4 = PTC.Y > Height - 7
  95.  
  96.         If F1 And F3 Then Return New Pointer(Cursors.SizeNWSE, 13)
  97.         If F1 And F4 Then Return New Pointer(Cursors.SizeNESW, 16)
  98.         If F2 And F3 Then Return New Pointer(Cursors.SizeNESW, 14)
  99.         If F2 And F4 Then Return New Pointer(Cursors.SizeNWSE, 17)
  100.         If F1 Then Return New Pointer(Cursors.SizeWE, 10)
  101.         If F2 Then Return New Pointer(Cursors.SizeWE, 11)
  102.         If F3 Then Return New Pointer(Cursors.SizeNS, 12)
  103.         If F4 Then Return New Pointer(Cursors.SizeNS, 15)
  104.         Return New Pointer(Cursors.Default, 0)
  105.     End Function
  106.  
  107.     Private Current, Pending As Pointer
  108.     Private Sub SetCurrent()
  109.         Pending = GetPointer()
  110.         If Current.Position = Pending.Position Then Return
  111.         Current = GetPointer()
  112.         Cursor = Current.Cursor
  113.     End Sub
  114.  
  115.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  116.         If _Resizable Then SetCurrent()
  117.         MyBase.OnMouseMove(e)
  118.     End Sub
  119.  
  120.     Protected Header As Rectangle
  121.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  122.         If Width = 0 OrElse Height = 0 Then Return
  123.         Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  124.         Invalidate()
  125.         MyBase.OnSizeChanged(e)
  126.     End Sub
  127.  
  128. #End Region
  129.  
  130. #Region " Convienence "
  131.  
  132.     MustOverride Sub PaintHook()
  133.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  134.         If Width = 0 OrElse Height = 0 Then Return
  135.         G = e.Graphics
  136.         PaintHook()
  137.     End Sub
  138.  
  139.     Private _TransparencyKey As Color
  140.     Property TransparencyKey() As Color
  141.         Get
  142.             Return _TransparencyKey
  143.         End Get
  144.         Set(ByVal v As Color)
  145.             _TransparencyKey = v
  146.             Invalidate()
  147.         End Set
  148.     End Property
  149.  
  150.     Private _Image As Image
  151.     Property Image() As Image
  152.         Get
  153.             Return _Image
  154.         End Get
  155.         Set(ByVal value As Image)
  156.             _Image = value
  157.             Invalidate()
  158.         End Set
  159.     End Property
  160.     ReadOnly Property ImageWidth() As Integer
  161.         Get
  162.             If _Image Is Nothing Then Return 0
  163.             Return _Image.Width
  164.         End Get
  165.     End Property
  166.  
  167.     Private _Size As Size
  168.     Private _Rectangle As Rectangle
  169.     Private _Gradient As LinearGradientBrush
  170.     Private _Brush As SolidBrush
  171.  
  172.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  173.         _Brush = New SolidBrush(c)
  174.         G.FillRectangle(_Brush, rect.X, rect.Y, 1, 1)
  175.         G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y, 1, 1)
  176.         G.FillRectangle(_Brush, rect.X, rect.Y + (rect.Height - 1), 1, 1)
  177.         G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), 1, 1)
  178.     End Sub
  179.  
  180.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  181.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  182.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  183.     End Sub
  184.  
  185.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  186.         DrawText(a, c, x, 0)
  187.     End Sub
  188.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  189.         If String.IsNullOrEmpty(Text) Then Return
  190.         _Size = G.MeasureString(Text, Font).ToSize
  191.         _Brush = New SolidBrush(c)
  192.  
  193.         Select Case a
  194.             Case HorizontalAlignment.Left
  195.                 G.DrawString(Text, Font, _Brush, x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  196.             Case HorizontalAlignment.Right
  197.                 G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  198.             Case HorizontalAlignment.Center
  199.                 G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  200.         End Select
  201.     End Sub
  202.  
  203.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  204.         DrawIcon(a, x, 0)
  205.     End Sub
  206.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  207.         If _Image Is Nothing Then Return
  208.         Select Case a
  209.             Case HorizontalAlignment.Left
  210.                 G.DrawImage(_Image, x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  211.             Case HorizontalAlignment.Right
  212.                 G.DrawImage(_Image, Width - _Image.Width - x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  213.             Case HorizontalAlignment.Center
  214.                 G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, _MoveHeight \ 2 - _Image.Height \ 2)
  215.         End Select
  216.     End Sub
  217.  
  218.     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)
  219.         _Rectangle = New Rectangle(x, y, width, height)
  220.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  221.         G.FillRectangle(_Gradient, _Rectangle)
  222.     End Sub
  223.  
  224. #End Region
  225.  
  226. End Class
  227. MustInherit Class ThemeControl
  228.     Inherits Control
  229.  
  230. #Region " Initialization "
  231.  
  232.     Protected G As Graphics, B As Bitmap
  233.     Sub New()
  234.         SetStyle(DirectCast(139270, ControlStyles), True)
  235.         B = New Bitmap(1, 1)
  236.         G = Graphics.FromImage(B)
  237.     End Sub
  238.  
  239.     Sub AllowTransparent()
  240.         SetStyle(ControlStyles.Opaque, False)
  241.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  242.     End Sub
  243.  
  244.     Overrides Property Text As String
  245.         Get
  246.             Return MyBase.Text
  247.         End Get
  248.         Set(ByVal v As String)
  249.             MyBase.Text = v
  250.             Invalidate()
  251.         End Set
  252.     End Property
  253. #End Region
  254.  
  255. #Region " Mouse Handling "
  256.  
  257.     Protected Enum State As Byte
  258.         MouseNone = 0
  259.         MouseOver = 1
  260.         MouseDown = 2
  261.     End Enum
  262.  
  263.     Protected MouseState As State
  264.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  265.         ChangeMouseState(State.MouseNone)
  266.         MyBase.OnMouseLeave(e)
  267.     End Sub
  268.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  269.         ChangeMouseState(State.MouseOver)
  270.         MyBase.OnMouseEnter(e)
  271.     End Sub
  272.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  273.         ChangeMouseState(State.MouseOver)
  274.         MyBase.OnMouseUp(e)
  275.     End Sub
  276.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  277.         If e.Button = MouseButtons.Left Then ChangeMouseState(State.MouseDown)
  278.         MyBase.OnMouseDown(e)
  279.     End Sub
  280.  
  281.     Private Sub ChangeMouseState(ByVal e As State)
  282.         MouseState = e
  283.         Invalidate()
  284.     End Sub
  285.  
  286. #End Region
  287.  
  288. #Region " Convienence "
  289.  
  290.     MustOverride Sub PaintHook()
  291.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  292.         If Width = 0 OrElse Height = 0 Then Return
  293.         PaintHook()
  294.         e.Graphics.DrawImage(B, 0, 0)
  295.     End Sub
  296.  
  297.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  298.         If Not Width = 0 AndAlso Not Height = 0 Then
  299.             B = New Bitmap(Width, Height)
  300.             G = Graphics.FromImage(B)
  301.             Invalidate()
  302.         End If
  303.         MyBase.OnSizeChanged(e)
  304.     End Sub
  305.  
  306.     Private _NoRounding As Boolean
  307.     Property NoRounding() As Boolean
  308.         Get
  309.             Return _NoRounding
  310.         End Get
  311.         Set(ByVal v As Boolean)
  312.             _NoRounding = v
  313.             Invalidate()
  314.         End Set
  315.     End Property
  316.  
  317.     Private _Image As Image
  318.     Property Image() As Image
  319.         Get
  320.             Return _Image
  321.         End Get
  322.         Set(ByVal value As Image)
  323.             _Image = value
  324.             Invalidate()
  325.         End Set
  326.     End Property
  327.     ReadOnly Property ImageWidth() As Integer
  328.         Get
  329.             If _Image Is Nothing Then Return 0
  330.             Return _Image.Width
  331.         End Get
  332.     End Property
  333.     ReadOnly Property ImageTop() As Integer
  334.         Get
  335.             If _Image Is Nothing Then Return 0
  336.             Return Height \ 2 - _Image.Height \ 2
  337.         End Get
  338.     End Property
  339.  
  340.     Private _Size As Size
  341.     Private _Rectangle As Rectangle
  342.     Private _Gradient As LinearGradientBrush
  343.     Private _Brush As SolidBrush
  344.  
  345.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  346.         If _NoRounding Then Return
  347.  
  348.         B.SetPixel(rect.X, rect.Y, c)
  349.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  350.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  351.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  352.     End Sub
  353.  
  354.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  355.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  356.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  357.     End Sub
  358.  
  359.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  360.         DrawText(a, c, x, 0)
  361.     End Sub
  362.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  363.         If String.IsNullOrEmpty(Text) Then Return
  364.         _Size = G.MeasureString(Text, Font).ToSize
  365.         _Brush = New SolidBrush(c)
  366.  
  367.         Select Case a
  368.             Case HorizontalAlignment.Left
  369.                 G.DrawString(Text, Font, _Brush, x, Height \ 2 - _Size.Height \ 2 + y)
  370.             Case HorizontalAlignment.Right
  371.                 G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, Height \ 2 - _Size.Height \ 2 + y)
  372.             Case HorizontalAlignment.Center
  373.                 G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, Height \ 2 - _Size.Height \ 2 + y)
  374.         End Select
  375.     End Sub
  376.  
  377.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  378.         DrawIcon(a, x, 0)
  379.     End Sub
  380.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  381.         If _Image Is Nothing Then Return
  382.         Select Case a
  383.             Case HorizontalAlignment.Left
  384.                 G.DrawImage(_Image, x, Height \ 2 - _Image.Height \ 2 + y)
  385.             Case HorizontalAlignment.Right
  386.                 G.DrawImage(_Image, Width - _Image.Width - x, Height \ 2 - _Image.Height \ 2 + y)
  387.             Case HorizontalAlignment.Center
  388.                 G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, Height \ 2 - _Image.Height \ 2)
  389.         End Select
  390.     End Sub
  391.  
  392.     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)
  393.         _Rectangle = New Rectangle(x, y, width, height)
  394.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  395.         G.FillRectangle(_Gradient, _Rectangle)
  396.     End Sub
  397. #End Region
  398.  
  399. End Class
  400. MustInherit Class ThemeContainerControl
  401.     Inherits ContainerControl
  402.  
  403. #Region " Initialization "
  404.  
  405.     Protected G As Graphics, B As Bitmap
  406.     Sub New()
  407.         SetStyle(DirectCast(139270, ControlStyles), True)
  408.         B = New Bitmap(1, 1)
  409.         G = Graphics.FromImage(B)
  410.     End Sub
  411.  
  412.     Sub AllowTransparent()
  413.         SetStyle(ControlStyles.Opaque, False)
  414.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  415.     End Sub
  416.  
  417. #End Region
  418.  
  419. #Region " Convienence "
  420.  
  421.     MustOverride Sub PaintHook()
  422.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  423.         If Width = 0 OrElse Height = 0 Then Return
  424.         PaintHook()
  425.         e.Graphics.DrawImage(B, 0, 0)
  426.     End Sub
  427.  
  428.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  429.         If Not Width = 0 AndAlso Not Height = 0 Then
  430.             B = New Bitmap(Width, Height)
  431.             G = Graphics.FromImage(B)
  432.             Invalidate()
  433.         End If
  434.         MyBase.OnSizeChanged(e)
  435.     End Sub
  436.  
  437.     Private _NoRounding As Boolean
  438.     Property NoRounding() As Boolean
  439.         Get
  440.             Return _NoRounding
  441.         End Get
  442.         Set(ByVal v As Boolean)
  443.             _NoRounding = v
  444.             Invalidate()
  445.         End Set
  446.     End Property
  447.  
  448.     Private _Rectangle As Rectangle
  449.     Private _Gradient As LinearGradientBrush
  450.  
  451.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  452.         If _NoRounding Then Return
  453.         B.SetPixel(rect.X, rect.Y, c)
  454.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  455.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  456.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  457.     End Sub
  458.  
  459.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  460.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  461.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  462.     End Sub
  463.  
  464.     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)
  465.         _Rectangle = New Rectangle(x, y, width, height)
  466.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  467.         G.FillRectangle(_Gradient, _Rectangle)
  468.     End Sub
  469. #End Region
  470.  
  471. End Class
  472. Public Class Draw
  473.     Shared Sub Gradient(ByVal g As Graphics, ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  474.         Dim R As New Rectangle(x, y, width, height)
  475.         Using T As New LinearGradientBrush(R, c1, c2, LinearGradientMode.Vertical)
  476.             g.FillRectangle(T, R)
  477.         End Using
  478.     End Sub
  479.     Shared Sub Gradient(ByVal g As Graphics, ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  480.         Using T As New LinearGradientBrush(R, c1, c2, LinearGradientMode.Vertical)
  481.             g.FillRectangle(T, R)
  482.         End Using
  483.     End Sub
  484.     Shared Sub Blend(ByVal g As Graphics, ByVal c1 As Color, ByVal c2 As Color, ByVal c3 As Color, ByVal c As Single, ByVal d As Integer, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  485.         Dim v As New ColorBlend(3)
  486.         V.Colors = New Color() {c1, c2, c3}
  487.         V.Positions = New Single() {0, c, 1}
  488.         Dim R As New Rectangle(x, y, width, height)
  489.         Using T As New LinearGradientBrush(R, c1, c1, CType(d, LinearGradientMode))
  490.             T.InterpolationColors = v : g.FillRectangle(T, R)
  491.         End Using
  492.     End Sub
  493.     Shared Function RoundedRectangle(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal cornerwidth As Integer, ByVal PenWidth As Integer) As GraphicsPath
  494.         Dim p As New GraphicsPath
  495.         p.StartFigure()
  496.         p.AddArc(New Rectangle(x, y, cornerwidth, cornerwidth), 180, 90)
  497.         p.AddLine(cornerwidth, y, width - cornerwidth - PenWidth, y)
  498.  
  499.         p.AddArc(New Rectangle(width - cornerwidth - PenWidth, y, cornerwidth, cornerwidth), -90, 90)
  500.         p.AddLine(width - PenWidth, cornerwidth, width - PenWidth, height - cornerwidth - PenWidth)
  501.  
  502.         p.AddArc(New Rectangle(width - cornerwidth - PenWidth, height - cornerwidth - PenWidth, cornerwidth, cornerwidth), 0, 90)
  503.         p.AddLine(width - cornerwidth - PenWidth, height - PenWidth, cornerwidth, height - PenWidth)
  504.  
  505.         p.AddArc(New Rectangle(x, height - cornerwidth - PenWidth, cornerwidth, cornerwidth), 90, 90)
  506.         p.CloseFigure()
  507.  
  508.         Return p
  509.     End Function
  510.  
  511.     Shared Sub BackGround(ByVal width As Integer, ByVal height As Integer, ByVal G As Graphics)
  512.  
  513.         Dim P1 As Color = Color.FromArgb(29, 25, 22)
  514.         Dim P2 As Color = Color.FromArgb(35, 31, 28)
  515.  
  516.         For y As Integer = 0 To height Step 4
  517.             For x As Integer = 0 To width Step 4
  518.                 G.FillRectangle(New SolidBrush(P1), New Rectangle(x, y, 1, 1))
  519.                 G.FillRectangle(New SolidBrush(P2), New Rectangle(x, y + 1, 1, 1))
  520.                 Try
  521.                     G.FillRectangle(New SolidBrush(P1), New Rectangle(x + 2, y + 2, 1, 1))
  522.                     G.FillRectangle(New SolidBrush(P2), New Rectangle(x + 2, y + 3, 1, 1))
  523.                 Catch
  524.                 End Try
  525.             Next
  526.         Next
  527.     End Sub
  528. End Class
  529. Class PurityxTheme
  530.     Inherits Theme
  531.  
  532.     Sub New()
  533.         Resizable = False
  534.         BackColor = Color.FromKnownColor(KnownColor.Control)
  535.         MoveHeight = 25
  536.         TransparencyKey = Color.Fuchsia
  537.     End Sub
  538.  
  539.     Public Overrides Sub PaintHook()
  540.         G.Clear(BackColor)   ' Clear the form first
  541.  
  542.         'DrawGradient(Color.FromArgb(64, 64, 64), Color.FromArgb(32, 32, 32), 0, 0, Width, Height, 90S)   ' Form Gradient
  543.         G.Clear(Color.FromArgb(60, 60, 60))
  544.         DrawGradient(Color.FromArgb(45, 40, 45), Color.FromArgb(32, 32, 32), 0, 0, Width, 25, 90S)   ' Form Top Bar
  545.  
  546.         G.DrawLine(Pens.Black, 0, 25, Width, 25)   ' Top Line
  547.         'G.DrawLine(Pens.Black, 0, Height - 25, Width, Height - 25)   ' Bottom Line
  548.  
  549.         DrawCorners(Color.Fuchsia, ClientRectangle)   ' Then draw some clean corners
  550.         DrawBorders(Pens.Black, Pens.DimGray, ClientRectangle)   ' Then we draw our form borders
  551.  
  552.         DrawText(HorizontalAlignment.Left, Color.Red, 7, 1)   ' Finally, we draw our text
  553.     End Sub
  554. End Class ' Theme Code
  555. Class PurityxButton
  556.     Inherits ThemeControl
  557.  
  558.     Overrides Sub PaintHook()
  559.         Select Case MouseState
  560.             Case State.MouseNone
  561.                 G.Clear(Color.Red)
  562.                 DrawGradient(Color.FromArgb(62, 62, 62), Color.FromArgb(38, 38, 38), 0, 0, Width, Height, 90S)
  563.             Case State.MouseOver
  564.                 G.Clear(Color.Red)
  565.                 DrawGradient(Color.FromArgb(62, 62, 62), Color.FromArgb(38, 38, 38), 0, 0, Width, Height, 90S)
  566.             Case State.MouseDown
  567.                 G.Clear(Color.DarkRed)
  568.                 DrawGradient(Color.FromArgb(38, 38, 38), Color.FromArgb(62, 62, 62), 0, 0, Width, Height, 90S)
  569.         End Select
  570.  
  571.         DrawBorders(Pens.Black, Pens.DimGray, ClientRectangle)   ' Form Border
  572.         DrawCorners(Color.Black, ClientRectangle)   ' Clean Corners
  573.         DrawText(HorizontalAlignment.Center, Color.Red, 0)
  574.     End Sub
  575. End Class ' Button Code
  576. Public Class PurityxLabel
  577.     Inherits Label
  578.     Sub New()
  579.         Font = New Font("Arial", 8)
  580.         ForeColor = Color.Red
  581.         BackColor = Color.Transparent
  582.     End Sub
  583. End Class ' Label Code
  584. Public Class PurityxSeperator
  585.     Inherits Control
  586.  
  587.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  588.         Using b As New Bitmap(Width, Height)
  589.             Using g As Graphics = Graphics.FromImage(b)
  590.                 g.Clear(BackColor)
  591.  
  592.                 Dim P1 As Color = Color.FromArgb(255, 255, 255)
  593.                 Dim P2 As Color = Color.FromArgb(255, 255, 255)
  594.                 g.FillRectangle(New SolidBrush(Color.FromArgb(62, 62, 62)), New Rectangle(0, 0, Width, Height))
  595.  
  596.  
  597.                 Dim GRec As New Rectangle(0, Height / 2, Width / 5, 2)
  598.                 Using GBrush As LinearGradientBrush = New LinearGradientBrush(GRec, Color.Transparent, P2, LinearGradientMode.Horizontal)
  599.                     g.FillRectangle(GBrush, GRec)
  600.                 End Using
  601.                 g.DrawLine(New Pen(P2, 2), New Point(GRec.Width, GRec.Y + 1), New Point(Width - GRec.Width + 1, GRec.Y + 1))
  602.  
  603.                 GRec = New Rectangle(Width - (Width / 5), Height / 2, Width / 5, 2)
  604.                 Using GBrush As LinearGradientBrush = New LinearGradientBrush(GRec, P2, Color.Transparent, LinearGradientMode.Horizontal)
  605.                     g.FillRectangle(GBrush, GRec)
  606.                 End Using
  607.                 e.Graphics.DrawImage(b, 0, 0)
  608.             End Using
  609.         End Using
  610.         MyBase.OnPaint(e)
  611.     End Sub
  612. End Class ' Seperator Code
  613. Class PurityxGroupbox
  614.     Inherits Panel
  615.     Dim Bg As Color = Color.FromArgb(62, 62, 62)
  616.     Dim PC2 As Color = Color.FromArgb(204, 204, 204)
  617.     Dim FC As Color = Color.FromArgb(204, 204, 204)
  618.     Dim p As Pen
  619.     Dim sb As SolidBrush
  620.     Sub New()
  621.         BackColor = Bg
  622.     End Sub
  623.     Dim _t As String = ""
  624.     Public Property Header() As String
  625.         Get
  626.             Return _t
  627.         End Get
  628.         Set(ByVal value As String)
  629.             _t = value
  630.             Invalidate()
  631.         End Set
  632.     End Property
  633.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  634.         Using b As New Bitmap(Width, Height)
  635.             Using g As Graphics = Graphics.FromImage(b)
  636.                 p = New Pen(PC2)
  637.                 sb = New SolidBrush(Bg)
  638.                 Dim M As SizeF = g.MeasureString(_t, Font)
  639.                 Dim Outline As GraphicsPath = Draw.RoundedRectangle(0, M.Height / 2, Width - 1, Height - 1, 10, 1)
  640.                 g.Clear(BackColor)
  641.                 g.FillRectangle(sb, New Rectangle(0, M.Height / 2, Width - 1, Height - 1))
  642.                 g.DrawPath(p, Outline)
  643.  
  644.                 g.FillRectangle(sb, New Rectangle(10, (M.Height / 2) - 2, M.Width + 10, M.Height))
  645.                 sb = New SolidBrush(FC)
  646.                 g.DrawString(MyBase.Text, MyBase.Font, Brushes.White, 7, 1)
  647.                 e.Graphics.DrawImage(b, 0, 0)
  648.             End Using
  649.         End Using
  650.         MyBase.OnPaint(e)
  651.     End Sub
  652. End Class ' GroupBox Code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement