Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Custom .Net GTheme by Aeonhack

By: a guest on May 30th, 2011  |  syntax: None  |  size: 17.46 KB  |  views: 628  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. 'Creator: Aeonhack
  2. 'Date: 4/23/2011
  3. 'Site: www.elitevs.net
  4. 'Version: 1.4
  5.  
  6. 'This is the fixed version. -aeon
  7.  
  8. Imports System.Drawing.Drawing2D
  9. Imports System.ComponentModel
  10. Imports System.Runtime.InteropServices
  11.  
  12.  
  13. MustInherit Class Theme
  14.     Inherits ContainerControl
  15.  
  16. #Region " Initialization "
  17.  
  18.     Protected G As Graphics
  19.     Sub New()
  20.         SetStyle(DirectCast(139270, ControlStyles), True)
  21.     End Sub
  22.  
  23.     Private ParentIsForm As Boolean
  24.     Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  25.         Dock = DockStyle.Fill
  26.         ParentIsForm = TypeOf Parent Is Form
  27.         If ParentIsForm Then
  28.             If Not _TransparencyKey = Color.Empty Then ParentForm.TransparencyKey = _TransparencyKey
  29.             ParentForm.FormBorderStyle = FormBorderStyle.None
  30.         End If
  31.         MyBase.OnHandleCreated(e)
  32.     End Sub
  33.  
  34.     Overrides Property Text As String
  35.         Get
  36.             Return MyBase.Text
  37.         End Get
  38.         Set(ByVal v As String)
  39.             MyBase.Text = v
  40.             Invalidate()
  41.         End Set
  42.     End Property
  43. #End Region
  44.  
  45. #Region " Sizing and Movement "
  46.  
  47.     Private _Resizable As Boolean = True
  48.     Property Resizable() As Boolean
  49.         Get
  50.             Return _Resizable
  51.         End Get
  52.         Set(ByVal value As Boolean)
  53.             _Resizable = value
  54.         End Set
  55.     End Property
  56.  
  57.     Private _MoveHeight As Integer = 24
  58.     Property MoveHeight() As Integer
  59.         Get
  60.             Return _MoveHeight
  61.         End Get
  62.         Set(ByVal v As Integer)
  63.             _MoveHeight = v
  64.             Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  65.         End Set
  66.     End Property
  67.  
  68.     Private Flag As IntPtr
  69.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  70.         If Not e.Button = MouseButtons.Left Then Return
  71.         If ParentIsForm Then If ParentForm.WindowState = FormWindowState.Maximized Then Return
  72.  
  73.         If Header.Contains(e.Location) Then
  74.             Flag = New IntPtr(2)
  75.         ElseIf Current.Position = 0 Or Not _Resizable Then
  76.             Return
  77.         Else
  78.             Flag = New IntPtr(Current.Position)
  79.         End If
  80.  
  81.         Capture = False
  82.         DefWndProc(Message.Create(Parent.Handle, 161, Flag, Nothing))
  83.  
  84.         MyBase.OnMouseDown(e)
  85.     End Sub
  86.  
  87.     Private Structure Pointer
  88.         ReadOnly Cursor As Cursor, Position As Byte
  89.         Sub New(ByVal c As Cursor, ByVal p As Byte)
  90.             Cursor = c
  91.             Position = p
  92.         End Sub
  93.     End Structure
  94.  
  95.     Private F1, F2, F3, F4 As Boolean, PTC As Point
  96.     Private Function GetPointer() As Pointer
  97.         PTC = PointToClient(MousePosition)
  98.         F1 = PTC.X < 7
  99.         F2 = PTC.X > Width - 7
  100.         F3 = PTC.Y < 7
  101.         F4 = PTC.Y > Height - 7
  102.  
  103.         If F1 And F3 Then Return New Pointer(Cursors.SizeNWSE, 13)
  104.         If F1 And F4 Then Return New Pointer(Cursors.SizeNESW, 16)
  105.         If F2 And F3 Then Return New Pointer(Cursors.SizeNESW, 14)
  106.         If F2 And F4 Then Return New Pointer(Cursors.SizeNWSE, 17)
  107.         If F1 Then Return New Pointer(Cursors.SizeWE, 10)
  108.         If F2 Then Return New Pointer(Cursors.SizeWE, 11)
  109.         If F3 Then Return New Pointer(Cursors.SizeNS, 12)
  110.         If F4 Then Return New Pointer(Cursors.SizeNS, 15)
  111.         Return New Pointer(Cursors.Default, 0)
  112.     End Function
  113.  
  114.     Private Current, Pending As Pointer
  115.     Private Sub SetCurrent()
  116.         Pending = GetPointer()
  117.         If Current.Position = Pending.Position Then Return
  118.         Current = GetPointer()
  119.         Cursor = Current.Cursor
  120.     End Sub
  121.  
  122.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  123.         If _Resizable Then SetCurrent()
  124.         MyBase.OnMouseMove(e)
  125.     End Sub
  126.  
  127.     Protected Header As Rectangle
  128.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  129.         If Width = 0 OrElse Height = 0 Then Return
  130.         Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  131.         Invalidate()
  132.         MyBase.OnSizeChanged(e)
  133.     End Sub
  134.  
  135. #End Region
  136.  
  137. #Region " Convienence "
  138.  
  139.     MustOverride Sub PaintHook()
  140.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  141.         If Width = 0 OrElse Height = 0 Then Return
  142.         G = e.Graphics
  143.         PaintHook()
  144.     End Sub
  145.  
  146.     Private _TransparencyKey As Color
  147.     Property TransparencyKey() As Color
  148.         Get
  149.             Return _TransparencyKey
  150.         End Get
  151.         Set(ByVal v As Color)
  152.             _TransparencyKey = v
  153.             Invalidate()
  154.         End Set
  155.     End Property
  156.  
  157.     Private _Image As Image
  158.     Property Image() As Image
  159.         Get
  160.             Return _Image
  161.         End Get
  162.         Set(ByVal value As Image)
  163.             _Image = value
  164.             Invalidate()
  165.         End Set
  166.     End Property
  167.     ReadOnly Property ImageWidth() As Integer
  168.         Get
  169.             If _Image Is Nothing Then Return 0
  170.             Return _Image.Width
  171.         End Get
  172.     End Property
  173.  
  174.     Private _Size As Size
  175.     Private _Rectangle As Rectangle
  176.     Private _Gradient As LinearGradientBrush
  177.     Private _Brush As SolidBrush
  178.  
  179.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  180.         _Brush = New SolidBrush(c)
  181.         G.FillRectangle(_Brush, rect.X, rect.Y, 1, 1)
  182.         G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y, 1, 1)
  183.         G.FillRectangle(_Brush, rect.X, rect.Y + (rect.Height - 1), 1, 1)
  184.         G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), 1, 1)
  185.     End Sub
  186.  
  187.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  188.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  189.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  190.     End Sub
  191.  
  192.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  193.         DrawText(a, c, x, 0)
  194.     End Sub
  195.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  196.         If String.IsNullOrEmpty(Text) Then Return
  197.         _Size = G.MeasureString(Text, Font).ToSize
  198.         _Brush = New SolidBrush(c)
  199.  
  200.         Select Case a
  201.             Case HorizontalAlignment.Left
  202.                 G.DrawString(Text, Font, _Brush, x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  203.             Case HorizontalAlignment.Right
  204.                 G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  205.             Case HorizontalAlignment.Center
  206.                 G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  207.         End Select
  208.     End Sub
  209.  
  210.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  211.         DrawIcon(a, x, 0)
  212.     End Sub
  213.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  214.         If _Image Is Nothing Then Return
  215.         Select Case a
  216.             Case HorizontalAlignment.Left
  217.                 G.DrawImage(_Image, x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  218.             Case HorizontalAlignment.Right
  219.                 G.DrawImage(_Image, Width - _Image.Width - x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  220.             Case HorizontalAlignment.Center
  221.                 G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, _MoveHeight \ 2 - _Image.Height \ 2)
  222.         End Select
  223.     End Sub
  224.  
  225.     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)
  226.         _Rectangle = New Rectangle(x, y, width, height)
  227.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  228.         G.FillRectangle(_Gradient, _Rectangle)
  229.     End Sub
  230.  
  231. #End Region
  232.  
  233. End Class
  234. MustInherit Class ThemeControl
  235.     Inherits Control
  236.  
  237. #Region " Initialization "
  238.  
  239.     Protected G As Graphics, B As Bitmap
  240.     Sub New()
  241.         SetStyle(DirectCast(139270, ControlStyles), True)
  242.         B = New Bitmap(1, 1)
  243.         G = Graphics.FromImage(B)
  244.     End Sub
  245.  
  246.     Sub AllowTransparent()
  247.         SetStyle(ControlStyles.Opaque, False)
  248.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  249.     End Sub
  250.  
  251.     Overrides Property Text As String
  252.         Get
  253.             Return MyBase.Text
  254.         End Get
  255.         Set(ByVal v As String)
  256.             MyBase.Text = v
  257.             Invalidate()
  258.         End Set
  259.     End Property
  260. #End Region
  261.  
  262. #Region " Mouse Handling "
  263.  
  264.     Protected Enum State As Byte
  265.         MouseNone = 0
  266.         MouseOver = 1
  267.         MouseDown = 2
  268.     End Enum
  269.  
  270.     Protected MouseState As State
  271.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  272.         ChangeMouseState(State.MouseNone)
  273.         MyBase.OnMouseLeave(e)
  274.     End Sub
  275.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  276.         ChangeMouseState(State.MouseOver)
  277.         MyBase.OnMouseEnter(e)
  278.     End Sub
  279.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  280.         ChangeMouseState(State.MouseOver)
  281.         MyBase.OnMouseUp(e)
  282.     End Sub
  283.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  284.         If e.Button = MouseButtons.Left Then ChangeMouseState(State.MouseDown)
  285.         MyBase.OnMouseDown(e)
  286.     End Sub
  287.  
  288.     Private Sub ChangeMouseState(ByVal e As State)
  289.         MouseState = e
  290.         Invalidate()
  291.     End Sub
  292.  
  293. #End Region
  294.  
  295. #Region " Convienence "
  296.  
  297.     MustOverride Sub PaintHook()
  298.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  299.         If Width = 0 OrElse Height = 0 Then Return
  300.         PaintHook()
  301.         e.Graphics.DrawImage(B, 0, 0)
  302.     End Sub
  303.  
  304.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  305.         If Not Width = 0 AndAlso Not Height = 0 Then
  306.             B = New Bitmap(Width, Height)
  307.             G = Graphics.FromImage(B)
  308.             Invalidate()
  309.         End If
  310.         MyBase.OnSizeChanged(e)
  311.     End Sub
  312.  
  313.     Private _NoRounding As Boolean
  314.     Property NoRounding() As Boolean
  315.         Get
  316.             Return _NoRounding
  317.         End Get
  318.         Set(ByVal v As Boolean)
  319.             _NoRounding = v
  320.             Invalidate()
  321.         End Set
  322.     End Property
  323.  
  324.     Private _Image As Image
  325.     Property Image() As Image
  326.         Get
  327.             Return _Image
  328.         End Get
  329.         Set(ByVal value As Image)
  330.             _Image = value
  331.             Invalidate()
  332.         End Set
  333.     End Property
  334.     ReadOnly Property ImageWidth() As Integer
  335.         Get
  336.             If _Image Is Nothing Then Return 0
  337.             Return _Image.Width
  338.         End Get
  339.     End Property
  340.     ReadOnly Property ImageTop() As Integer
  341.         Get
  342.             If _Image Is Nothing Then Return 0
  343.             Return Height \ 2 - _Image.Height \ 2
  344.         End Get
  345.     End Property
  346.  
  347.     Private _Size As Size
  348.     Private _Rectangle As Rectangle
  349.     Private _Gradient As LinearGradientBrush
  350.     Private _Brush As SolidBrush
  351.  
  352.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  353.         If _NoRounding Then Return
  354.  
  355.         B.SetPixel(rect.X, rect.Y, c)
  356.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  357.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  358.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  359.     End Sub
  360.  
  361.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  362.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  363.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  364.     End Sub
  365.  
  366.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  367.         DrawText(a, c, x, 0)
  368.     End Sub
  369.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  370.         If String.IsNullOrEmpty(Text) Then Return
  371.         _Size = G.MeasureString(Text, Font).ToSize
  372.         _Brush = New SolidBrush(c)
  373.  
  374.         Select Case a
  375.             Case HorizontalAlignment.Left
  376.                 G.DrawString(Text, Font, _Brush, x, Height \ 2 - _Size.Height \ 2 + y)
  377.             Case HorizontalAlignment.Right
  378.                 G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, Height \ 2 - _Size.Height \ 2 + y)
  379.             Case HorizontalAlignment.Center
  380.                 G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, Height \ 2 - _Size.Height \ 2 + y)
  381.         End Select
  382.     End Sub
  383.  
  384.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  385.         DrawIcon(a, x, 0)
  386.     End Sub
  387.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  388.         If _Image Is Nothing Then Return
  389.         Select Case a
  390.             Case HorizontalAlignment.Left
  391.                 G.DrawImage(_Image, x, Height \ 2 - _Image.Height \ 2 + y)
  392.             Case HorizontalAlignment.Right
  393.                 G.DrawImage(_Image, Width - _Image.Width - x, Height \ 2 - _Image.Height \ 2 + y)
  394.             Case HorizontalAlignment.Center
  395.                 G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, Height \ 2 - _Image.Height \ 2)
  396.         End Select
  397.     End Sub
  398.  
  399.     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)
  400.         _Rectangle = New Rectangle(x, y, width, height)
  401.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  402.         G.FillRectangle(_Gradient, _Rectangle)
  403.     End Sub
  404. #End Region
  405.  
  406. End Class
  407. MustInherit Class ThemeContainerControl
  408.     Inherits ContainerControl
  409.  
  410. #Region " Initialization "
  411.  
  412.     Protected G As Graphics, B As Bitmap
  413.     Sub New()
  414.         SetStyle(DirectCast(139270, ControlStyles), True)
  415.         B = New Bitmap(1, 1)
  416.         G = Graphics.FromImage(B)
  417.     End Sub
  418.  
  419.     Sub AllowTransparent()
  420.         SetStyle(ControlStyles.Opaque, False)
  421.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  422.     End Sub
  423.  
  424. #End Region
  425.  
  426. #Region " Convienence "
  427.  
  428.     MustOverride Sub PaintHook()
  429.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  430.         If Width = 0 OrElse Height = 0 Then Return
  431.         PaintHook()
  432.         e.Graphics.DrawImage(B, 0, 0)
  433.     End Sub
  434.  
  435.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  436.         If Not Width = 0 AndAlso Not Height = 0 Then
  437.             B = New Bitmap(Width, Height)
  438.             G = Graphics.FromImage(B)
  439.             Invalidate()
  440.         End If
  441.         MyBase.OnSizeChanged(e)
  442.     End Sub
  443.  
  444.     Private _NoRounding As Boolean
  445.     Property NoRounding() As Boolean
  446.         Get
  447.             Return _NoRounding
  448.         End Get
  449.         Set(ByVal v As Boolean)
  450.             _NoRounding = v
  451.             Invalidate()
  452.         End Set
  453.     End Property
  454.  
  455.     Private _Rectangle As Rectangle
  456.     Private _Gradient As LinearGradientBrush
  457.  
  458.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  459.         If _NoRounding Then Return
  460.         B.SetPixel(rect.X, rect.Y, c)
  461.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  462.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  463.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  464.     End Sub
  465.  
  466.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  467.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  468.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  469.     End Sub
  470.  
  471.     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)
  472.         _Rectangle = New Rectangle(x, y, width, height)
  473.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  474.         G.FillRectangle(_Gradient, _Rectangle)
  475.     End Sub
  476. #End Region
  477.  
  478. End Class
  479.  
  480. Class GTheme
  481.     Inherits Theme
  482.  
  483.     Sub New()
  484.         MoveHeight = 29
  485.  
  486.         C1 = Color.FromArgb(41, 41, 41)
  487.         C2 = Color.FromArgb(25, 25, 25)
  488.  
  489.         P1 = New Pen(Color.FromArgb(58, 58, 58))
  490.         P2 = New Pen(C2)
  491.  
  492.         BackColor = C1
  493.         ForeColor = Color.FromArgb(100, 100, 100)
  494.         TransparencyKey = Color.Fuchsia
  495.     End Sub
  496.  
  497.     Private C1, C2 As Color
  498.     Private P1, P2 As Pen
  499.  
  500.     Overrides Sub PaintHook()
  501.         G.Clear(C1)
  502.  
  503.         DrawGradient(C2, C1, 0, 0, Width, 28, 90S)
  504.  
  505.         G.DrawLine(P2, 0, 28, Width, 28)
  506.         G.DrawLine(P1, 0, 29, Width, 29)
  507.  
  508.         DrawText(HorizontalAlignment.Left, ForeColor, 5 + ImageWidth)
  509.         DrawIcon(HorizontalAlignment.Left, 5)
  510.  
  511.         DrawBorders(Pens.Black, P1, ClientRectangle)
  512.         DrawCorners(Color.Fuchsia, ClientRectangle)
  513.     End Sub
  514.  
  515. End Class
  516. Class GButton
  517.     Inherits ThemeControl
  518.  
  519.     Private P1, P2 As Pen
  520.     Private C1, C2 As Color
  521.  
  522.     Sub New()
  523.         P1 = New Pen(Color.FromArgb(25, 25, 25))
  524.         P2 = New Pen(Color.FromArgb(11, Color.White))
  525.  
  526.         C1 = Color.FromArgb(41, 41, 41)
  527.         C2 = Color.FromArgb(51, 51, 51)
  528.     End Sub
  529.  
  530.     Overrides Sub PaintHook()
  531.  
  532.         If MouseState = State.MouseDown Then
  533.             DrawGradient(C1, C2, 0, 0, Width, Height, 90S)
  534.         Else
  535.             DrawGradient(C2, C1, 0, 0, Width, Height, 90S)
  536.         End If
  537.  
  538.         DrawText(HorizontalAlignment.Center, ForeColor, 0)
  539.         DrawIcon(HorizontalAlignment.Left, 0)
  540.  
  541.         DrawBorders(P1, P2, ClientRectangle)
  542.         DrawCorners(BackColor, ClientRectangle)
  543.     End Sub
  544.  
  545. End Class