Advertisement
Guest User

Modern, Pearl, and Electron Themes - Aeonhack

a guest
Jun 21st, 2011
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 16.54 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. Public Class Draw
  4.     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)
  5.         Dim R As New Rectangle(x, y, width, height)
  6.         Using T As New LinearGradientBrush(R, c1, c2, LinearGradientMode.Vertical)
  7.             g.FillRectangle(T, R)
  8.         End Using
  9.     End Sub
  10.     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)
  11.         Dim V As New ColorBlend(3)
  12.         V.Colors = New Color() {c1, c2, c3}
  13.         V.Positions = New Single() {0, c, 1}
  14.         Dim R As New Rectangle(x, y, width, height)
  15.         Using T As New LinearGradientBrush(R, c1, c1, CType(d, LinearGradientMode))
  16.             T.InterpolationColors = V : g.FillRectangle(T, R)
  17.         End Using
  18.     End Sub
  19. End Class
  20. 'Pearl Theme
  21. Public Class PTheme : Inherits Control
  22.     Private _TitleHeight As Integer = 25
  23.     Public Property TitleHeight() As Integer
  24.         Get
  25.             Return _TitleHeight
  26.         End Get
  27.         Set(ByVal v As Integer)
  28.             If v > Height Then v = Height
  29.             If v < 2 Then Height = 1
  30.             _TitleHeight = v : Invalidate()
  31.         End Set
  32.     End Property
  33.     Private _TitleAlign As HorizontalAlignment
  34.     Public Property TitleAlign() As HorizontalAlignment
  35.         Get
  36.             Return _TitleAlign
  37.         End Get
  38.         Set(ByVal v As HorizontalAlignment)
  39.             _TitleAlign = v : Invalidate()
  40.         End Set
  41.     End Property
  42.     Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  43.         Dock = 5
  44.         If TypeOf Parent Is Form Then CType(Parent, Form).FormBorderStyle = 0
  45.         MyBase.OnHandleCreated(e)
  46.     End Sub
  47.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  48.         If New Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(New Rectangle(MousePosition.X, MousePosition.Y, 1, 1)) Then
  49.             Capture = False : Dim M = Message.Create(Parent.Handle, 161, 2, 0) : DefWndProc(M)
  50.         End If : MyBase.OnMouseDown(e)
  51.     End Sub
  52.     Dim C1 As Color = Color.FromArgb(240, 240, 240), C2 As Color = Color.FromArgb(230, 230, 230), C3 As Color = Color.FromArgb(190, 190, 190)
  53.     Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  54.     End Sub
  55.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  56.         Using B As New Bitmap(Width, Height)
  57.             Using G = Graphics.FromImage(B)
  58.                 G.Clear(Color.FromArgb(245, 245, 245))
  59.  
  60.                 Draw.Blend(G, Color.White, C2, C1, 0.7, 1, 0, 0, Width, _TitleHeight)
  61.  
  62.                 G.FillRectangle(New SolidBrush(Color.FromArgb(80, 255, 255, 255)), 0, 0, Width, CInt(_TitleHeight / 2))
  63.                 G.DrawRectangle(New Pen(Color.FromArgb(100, 255, 255, 255)), 1, 1, Width - 3, _TitleHeight - 2)
  64.  
  65.                 Dim S = G.MeasureString(Text, Font), O = 6
  66.                 If _TitleAlign = 2 Then O = Width / 2 - S.Width / 2
  67.                 If _TitleAlign = 1 Then O = Width - S.Width - 6
  68.                 G.DrawString(Text, Font, New SolidBrush(C3), O, CInt(_TitleHeight / 2 - S.Height / 2))
  69.  
  70.                 G.DrawLine(New Pen(C3), 0, _TitleHeight, Width, _TitleHeight)
  71.                 G.DrawLine(Pens.White, 0, _TitleHeight + 1, Width, _TitleHeight + 1)
  72.                 G.DrawRectangle(New Pen(C3), 0, 0, Width - 1, Height - 1)
  73.  
  74.                 e.Graphics.DrawImage(B.Clone, 0, 0)
  75.             End Using
  76.         End Using
  77.     End Sub
  78. End Class
  79. Public Class PButton : Inherits Control
  80.     Sub New()
  81.         ForeColor = C3
  82.     End Sub
  83.     Private State As Integer
  84.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  85.         State = 1 : Invalidate() : MyBase.OnMouseEnter(e)
  86.     End Sub
  87.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  88.         State = 2 : Invalidate() : MyBase.OnMouseDown(e)
  89.     End Sub
  90.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  91.         State = 0 : Invalidate() : MyBase.OnMouseLeave(e)
  92.     End Sub
  93.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  94.         State = 1 : Invalidate() : MyBase.OnMouseUp(e)
  95.     End Sub
  96.     Dim C1 As Color = Color.FromArgb(240, 240, 240), C2 As Color = Color.FromArgb(230, 230, 230), C3 As Color = Color.FromArgb(190, 190, 190)
  97.     Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  98.     End Sub
  99.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  100.         Using B As New Bitmap(Width, Height)
  101.             Using G = Graphics.FromImage(B)
  102.                 If State = 2 Then
  103.                     Draw.Gradient(G, C2, Color.WhiteSmoke, 1, 1, Width, Height)
  104.                 Else
  105.                     Draw.Gradient(G, Color.WhiteSmoke, C2, 1, 1, Width, Height)
  106.                 End If
  107.  
  108.                 If State < 2 Then G.FillRectangle(New SolidBrush(Color.FromArgb(80, 255, 255, 255)), 0, 0, Width, CInt(Height * 0.3))
  109.  
  110.                 Dim S = G.MeasureString(Text, Font)
  111.                 G.DrawString(Text, Font, New SolidBrush(ForeColor), Width / 2 - S.Width / 2, Height / 2 - S.Height / 2)
  112.                 G.DrawRectangle(New Pen(C3), 0, 0, Width - 1, Height - 1)
  113.  
  114.                 e.Graphics.DrawImage(B.Clone, 0, 0)
  115.             End Using
  116.         End Using
  117.     End Sub
  118. End Class
  119. Public Class PProgress : Inherits Control
  120.     Private _Value As Integer
  121.     Public Property Value() As Integer
  122.         Get
  123.             Return _Value
  124.         End Get
  125.         Set(ByVal value As Integer)
  126.             _Value = value : Invalidate()
  127.         End Set
  128.     End Property
  129.     Private _Maximum As Integer = 100
  130.     Public Property Maximum() As Integer
  131.         Get
  132.             Return _Maximum
  133.         End Get
  134.         Set(ByVal value As Integer)
  135.             If value = 0 Then value = 1
  136.             _Maximum = value : Invalidate()
  137.         End Set
  138.     End Property
  139.     Dim C1 As Color = Color.FromArgb(240, 240, 240), C2 As Color = Color.FromArgb(230, 230, 230), C3 As Color = Color.FromArgb(190, 190, 190)
  140.     Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  141.     End Sub
  142.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  143.         Dim V As Integer = Width * _Value / _Maximum
  144.         Using B As New Bitmap(Width, Height)
  145.             Using G = Graphics.FromImage(B)
  146.                 Draw.Gradient(G, C2, C1, 1, 1, Width - 2, Height - 2)
  147.                 G.DrawRectangle(New Pen(C2), 1, 1, V - 3, Height - 3)
  148.                 Draw.Gradient(G, C1, C2, 2, 2, V - 4, Height - 4)
  149.  
  150.                 G.FillRectangle(New SolidBrush(Color.FromArgb(50, 255, 255, 255)), 2, 2, V - 4, CInt(Height / 2) - 2)
  151.                 G.DrawRectangle(New Pen(C3), 0, 0, Width - 1, Height - 1)
  152.  
  153.                 e.Graphics.DrawImage(B.Clone, 0, 0)
  154.             End Using
  155.         End Using
  156.     End Sub
  157. End Class
  158. 'Modern Theme
  159. Public Class MTheme : Inherits Control
  160.     Private _TitleHeight As Integer = 25
  161.     Public Property TitleHeight() As Integer
  162.         Get
  163.             Return _TitleHeight
  164.         End Get
  165.         Set(ByVal v As Integer)
  166.             If v > Height Then v = Height
  167.             If v < 2 Then Height = 1
  168.             _TitleHeight = v : Invalidate()
  169.         End Set
  170.     End Property
  171.     Private _TitleAlign As HorizontalAlignment = 2
  172.     Public Property TitleAlign() As HorizontalAlignment
  173.         Get
  174.             Return _TitleAlign
  175.         End Get
  176.         Set(ByVal v As HorizontalAlignment)
  177.             _TitleAlign = v : Invalidate()
  178.         End Set
  179.     End Property
  180.     Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  181.         Dock = 5
  182.         If TypeOf Parent Is Form Then CType(Parent, Form).FormBorderStyle = 0
  183.         MyBase.OnHandleCreated(e)
  184.     End Sub
  185.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  186.         If New Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(New Rectangle(MousePosition.X, MousePosition.Y, 1, 1)) Then
  187.             Capture = False : Dim M = Message.Create(Parent.Handle, 161, 2, 0) : DefWndProc(M)
  188.         End If : MyBase.OnMouseDown(e)
  189.     End Sub
  190.     Dim C1 As Color = Color.FromArgb(74, 74, 74), C2 As Color = Color.FromArgb(63, 63, 63), C3 As Color = Color.FromArgb(41, 41, 41), _
  191.     C4 As Color = Color.FromArgb(27, 27, 27), C5 As Color = Color.FromArgb(0, 0, 0, 0), C6 As Color = Color.FromArgb(25, 255, 255, 255)
  192.     Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  193.     End Sub
  194.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  195.         Using B As New Bitmap(Width, Height)
  196.             Using G = Graphics.FromImage(B)
  197.                 G.Clear(C3)
  198.  
  199.                 Draw.Gradient(G, C4, C3, 0, 0, Width, _TitleHeight)
  200.  
  201.                 Dim S = G.MeasureString(Text, Font), O = 6
  202.                 If _TitleAlign = 2 Then O = Width / 2 - S.Width / 2
  203.                 If _TitleAlign = 1 Then O = Width - S.Width - 6
  204.                 Dim R As New Rectangle(O, (_TitleHeight + 2) / 2 - S.Height / 2, S.Width, S.Height)
  205.                 Using T As New LinearGradientBrush(R, C1, C3, LinearGradientMode.Vertical)
  206.                     G.DrawString(Text, Font, T, R)
  207.                 End Using
  208.  
  209.                 G.DrawLine(New Pen(C3), 0, 1, Width, 1)
  210.  
  211.                 Draw.Blend(G, C5, C6, C5, 0.5, 0, 0, _TitleHeight + 1, Width, 1)
  212.  
  213.                 G.DrawLine(New Pen(C4), 0, _TitleHeight, Width, _TitleHeight)
  214.                 G.DrawRectangle(New Pen(C4), 0, 0, Width - 1, Height - 1)
  215.  
  216.                 e.Graphics.DrawImage(B.Clone, 0, 0)
  217.             End Using
  218.         End Using
  219.     End Sub
  220. End Class
  221. Public Class MButton : Inherits Control
  222.     Sub New()
  223.         ForeColor = Color.FromArgb(65, 65, 65)
  224.     End Sub
  225.     Private State As Integer
  226.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  227.         State = 1 : Invalidate() : MyBase.OnMouseEnter(e)
  228.     End Sub
  229.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  230.         State = 2 : Invalidate() : MyBase.OnMouseDown(e)
  231.     End Sub
  232.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  233.         State = 0 : Invalidate() : MyBase.OnMouseLeave(e)
  234.     End Sub
  235.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  236.         State = 1 : Invalidate() : MyBase.OnMouseUp(e)
  237.     End Sub
  238.     Dim C1 As Color = Color.FromArgb(31, 31, 31), C2 As Color = Color.FromArgb(41, 41, 41), C3 As Color = Color.FromArgb(51, 51, 51), _
  239.     C4 As Color = Color.FromArgb(0, 0, 0, 0), C5 As Color = Color.FromArgb(25, 255, 255, 255)
  240.     Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  241.     End Sub
  242.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  243.         Using B As New Bitmap(Width, Height)
  244.             Using G = Graphics.FromImage(B)
  245.                 G.DrawRectangle(New Pen(C1), 0, 0, Width - 1, Height - 1)
  246.  
  247.                 If State = 2 Then
  248.                     Draw.Gradient(G, C2, C3, 1, 1, Width - 2, Height - 2)
  249.                 Else
  250.                     Draw.Gradient(G, C3, C2, 1, 1, Width - 2, Height - 2)
  251.                 End If
  252.  
  253.                 Dim O = G.MeasureString(Text, Font)
  254.                 G.DrawString(Text, Font, New SolidBrush(ForeColor), Width / 2 - O.Width / 2, Height / 2 - O.Height / 2)
  255.  
  256.                 Draw.Blend(G, C4, C5, C4, 0.5, 0, 1, 1, Width - 2, 1)
  257.  
  258.                 e.Graphics.DrawImage(B.Clone, 0, 0)
  259.             End Using
  260.         End Using
  261.     End Sub
  262. End Class
  263. Public Class MProgress : Inherits Control
  264.     Private _Value As Integer
  265.     Public Property Value() As Integer
  266.         Get
  267.             Return _Value
  268.         End Get
  269.         Set(ByVal value As Integer)
  270.             _Value = value : Invalidate()
  271.         End Set
  272.     End Property
  273.     Private _Maximum As Integer = 100
  274.     Public Property Maximum() As Integer
  275.         Get
  276.             Return _Maximum
  277.         End Get
  278.         Set(ByVal value As Integer)
  279.             If value = 0 Then value = 1
  280.             _Maximum = value : Invalidate()
  281.         End Set
  282.     End Property
  283.     Dim C1 As Color = Color.FromArgb(31, 31, 31), C2 As Color = Color.FromArgb(41, 41, 41), C3 As Color = Color.FromArgb(51, 51, 51), _
  284.     C4 As Color = Color.FromArgb(0, 0, 0, 0), C5 As Color = Color.FromArgb(25, 255, 255, 255)
  285.     Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  286.     End Sub
  287.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  288.         Dim V As Integer = Width * _Value / _Maximum
  289.         Using B As New Bitmap(Width, Height)
  290.             Using G = Graphics.FromImage(B)
  291.                 Draw.Gradient(G, C2, C3, 1, 1, Width - 2, Height - 2)
  292.                 G.DrawRectangle(New Pen(C2), 1, 1, V - 3, Height - 3)
  293.                 Draw.Gradient(G, C3, C2, 2, 2, V - 4, Height - 4)
  294.  
  295.                 G.DrawRectangle(New Pen(C1), 0, 0, Width - 1, Height - 1)
  296.  
  297.                 e.Graphics.DrawImage(B.Clone, 0, 0)
  298.             End Using
  299.         End Using
  300.     End Sub
  301. End Class
  302. 'Electron Theme
  303. Public Class ETheme : Inherits Control
  304.     Private _TitleHeight As Integer = 25
  305.     Public Property TitleHeight() As Integer
  306.         Get
  307.             Return _TitleHeight
  308.         End Get
  309.         Set(ByVal v As Integer)
  310.             If v > Height Then v = Height
  311.             If v < 2 Then Height = 1
  312.             _TitleHeight = v : Invalidate()
  313.         End Set
  314.     End Property
  315.     Private _TitleAlign As HorizontalAlignment = 2
  316.     Public Property TitleAlign() As HorizontalAlignment
  317.         Get
  318.             Return _TitleAlign
  319.         End Get
  320.         Set(ByVal v As HorizontalAlignment)
  321.             _TitleAlign = v : Invalidate()
  322.         End Set
  323.     End Property
  324.     Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  325.         Dock = 5
  326.         If TypeOf Parent Is Form Then CType(Parent, Form).FormBorderStyle = 0
  327.         MyBase.OnHandleCreated(e)
  328.     End Sub
  329.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  330.         If New Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(New Rectangle(MousePosition.X, MousePosition.Y, 1, 1)) Then
  331.             Capture = False : Dim M = Message.Create(Parent.Handle, 161, 2, 0) : DefWndProc(M)
  332.         End If : MyBase.OnMouseDown(e)
  333.     End Sub
  334.     Dim C1 As Color = Color.FromArgb(0, 70, 114), C2 As Color = Color.FromArgb(0, 47, 78), C3 As Color = Color.FromArgb(0, 34, 57), _
  335.     C4 As Color = Color.FromArgb(0, 30, 50)
  336.     Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  337.     End Sub
  338.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  339.         Using B As New Bitmap(Width, Height)
  340.             Using G = Graphics.FromImage(B)
  341.                 G.Clear(C3)
  342.  
  343.                 Draw.Blend(G, C2, C3, C1, 0.5, 1, 0, 0, Width, _TitleHeight)
  344.  
  345.                 G.FillRectangle(New SolidBrush(Color.FromArgb(15, 255, 255, 255)), 1, 1, Width - 2, CInt(_TitleHeight / 2) - 2)
  346.                 G.DrawRectangle(New Pen(Color.FromArgb(35, 255, 255, 255)), 1, 1, Width - 3, _TitleHeight - 2)
  347.  
  348.                 Dim S = G.MeasureString(Text, Font), O = 6
  349.                 If _TitleAlign = 2 Then O = Width / 2 - S.Width / 2
  350.                 If _TitleAlign = 1 Then O = Width - S.Width - 14
  351.                 Dim V = CInt(_TitleHeight / 2 - (S.Height + 4) / 2)
  352.  
  353.                 Draw.Gradient(G, C3, C2, O, V, S.Width + 8, S.Height + 4)
  354.                 G.DrawRectangle(New Pen(C3), O, V, S.Width + 7, S.Height + 3)
  355.  
  356.                 Dim R As New Rectangle(O + 4, CInt(_TitleHeight / 2 - S.Height / 2), S.Width, S.Height)
  357.                 Using T As New LinearGradientBrush(R, C1, C2, LinearGradientMode.Vertical)
  358.                     G.DrawString(Text, Font, T, R)
  359.                 End Using
  360.  
  361.                 G.DrawRectangle(New Pen(C1), 1, _TitleHeight + 1, Width - 3, Height - _TitleHeight - 3)
  362.  
  363.                 G.DrawLine(New Pen(C4), 0, _TitleHeight, Width, _TitleHeight)
  364.                 G.DrawRectangle(New Pen(C4), 0, 0, Width - 1, Height - 1)
  365.                 e.Graphics.DrawImage(B.Clone, 0, 0)
  366.             End Using
  367.         End Using
  368.     End Sub
  369. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement