Advertisement
Guest User

Advanced SystemCare Theme

a guest
Jan 14th, 2014
6,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 22.63 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Imports System.ComponentModel
  3.  
  4. Module Drawing
  5.  
  6.     Public Function RoundRect(ByVal rect As Rectangle, ByVal slope As Integer) As GraphicsPath
  7.         Dim gp As GraphicsPath = New GraphicsPath()
  8.         Dim arcWidth As Integer = slope * 2
  9.         gp.AddArc(New Rectangle(rect.X, rect.Y, arcWidth, arcWidth), -180, 90)
  10.         gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Y, arcWidth, arcWidth), -90, 90)
  11.         gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 0, 90)
  12.         gp.AddArc(New Rectangle(rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 90, 90)
  13.         gp.CloseAllFigures()
  14.         Return gp
  15.     End Function
  16.  
  17. End Module
  18.  
  19. Module Prevent
  20.  
  21.     Public Sub Prevent(ByVal g As Graphics, ByVal w As Integer, ByVal h As Integer)
  22.         Dim txt As String = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String("VGhlbWUlMjBjcmVhdGVkJTIwYnklMjBIYXdrJTIwSEY=")).Replace("%20", " ")
  23.         Dim txtSize As SizeF = g.MeasureString(txt, New Font("Arial", 8))
  24.         g.DrawString(txt, New Font("Arial", 8), New SolidBrush(Color.FromArgb(125, 125, 125)), New Point(w - txtSize.Width - 6, h - txtSize.Height - 4))
  25.     End Sub
  26.  
  27. End Module
  28.  
  29. Class ascThemeContainer
  30.     Inherits ContainerControl
  31.  
  32.     Private moveHeight As Integer = 38
  33.     Private formCanMove As Boolean = False
  34.     Private mouseX, mouseY As Integer
  35.     Private overExit, overMin As Boolean
  36.  
  37.     Public Overrides Property Text() As String
  38.         Get
  39.             Return MyBase.Text
  40.         End Get
  41.         Set(ByVal value As String)
  42.             MyBase.Text = value
  43.             Invalidate()
  44.         End Set
  45.     End Property
  46.  
  47.     Sub New()
  48.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  49.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  50.         Dock = DockStyle.Fill
  51.         Font = New Font("Arial", 12, FontStyle.Bold Or FontStyle.Italic)
  52.         BackColor = Color.FromArgb(15, 15, 15)
  53.     End Sub
  54.  
  55.     Protected Overrides Sub CreateHandle()
  56.         MyBase.CreateHandle()
  57.         FindForm.FormBorderStyle = FormBorderStyle.None
  58.         If FindForm.TransparencyKey = Nothing Then FindForm.TransparencyKey = Color.Fuchsia
  59.     End Sub
  60.  
  61.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  62.         MyBase.OnPaint(e)
  63.  
  64.         Dim G As Graphics = e.Graphics
  65.         G.Clear(FindForm.TransparencyKey)
  66.  
  67.         Dim slope As Integer = 8
  68.  
  69.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  70.         Dim mainPath As GraphicsPath = RoundRect(mainRect, slope)
  71.         G.FillPath(New SolidBrush(BackColor), mainPath)
  72.         G.DrawPath(New Pen(Color.FromArgb(30, 35, 45)), mainPath)
  73.         G.FillPath(New SolidBrush(Color.FromArgb(30, 30, 40)), RoundRect(New Rectangle(0, 0, Width - 1, moveHeight - slope), slope))
  74.         G.FillRectangle(New SolidBrush(Color.FromArgb(30, 30, 40)), New Rectangle(0, moveHeight - (slope * 2), Width - 1, slope * 2))
  75.         G.DrawLine(New Pen(Color.FromArgb(60, 60, 60)), New Point(1, moveHeight), New Point(Width - 2, moveHeight))
  76.         G.SmoothingMode = SmoothingMode.HighQuality
  77.  
  78.         Dim textX As Integer = 6
  79.         Dim textY As Integer = (moveHeight / 2) - (G.MeasureString(Text, Font).Height / 2) + 1
  80.         Dim textSize As SizeF = G.MeasureString(Text, Font)
  81.         Dim textRect As New Rectangle(textX, textY, textSize.Width, textSize.Height)
  82.         Dim textBrush As New LinearGradientBrush(textRect, Color.FromArgb(185, 190, 195), Color.FromArgb(125, 125, 125), 90.0F)
  83.         G.DrawString(Text, Font, textBrush, New Point(textX, textY))
  84.  
  85.         If overExit Then
  86.             G.DrawString("r", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(25, 100, 140)), New Point(Width - 27, 11))
  87.         Else
  88.             G.DrawString("r", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(205, 210, 215)), New Point(Width - 27, 11))
  89.         End If
  90.         If overMin Then
  91.             G.DrawString("0", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(25, 100, 140)), New Point(Width - 47, 10))
  92.         Else
  93.             G.DrawString("0", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(205, 210, 215)), New Point(Width - 47, 10))
  94.         End If
  95.  
  96.         If DesignMode Then Prevent.Prevent(G, Width, Height)
  97.  
  98.     End Sub
  99.  
  100.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  101.         MyBase.OnMouseMove(e)
  102.  
  103.         If formCanMove = True Then
  104.             FindForm.Location = MousePosition - New Point(mouseX, mouseY)
  105.         End If
  106.  
  107.         If e.Y > 11 AndAlso e.Y < 24 Then
  108.             If e.X > Width - 23 AndAlso e.X < Width - 10 Then overExit = True Else overExit = False
  109.             If e.X > Width - 44 AndAlso e.X < Width - 31 Then overMin = True Else overMin = False
  110.         Else
  111.             overExit = False
  112.             overMin = False
  113.         End If
  114.  
  115.         Invalidate()
  116.  
  117.     End Sub
  118.  
  119.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  120.         MyBase.OnMouseDown(e)
  121.  
  122.         mouseX = e.X
  123.         mouseY = e.Y
  124.  
  125.         If e.Y <= moveHeight AndAlso overExit = False AndAlso overMin = False Then formCanMove = True
  126.  
  127.         If overExit Then
  128.             FindForm.Close()
  129.         ElseIf overMin Then
  130.             FindForm.WindowState = FormWindowState.Minimized
  131.             overExit = False
  132.             overMin = False
  133.         Else
  134.             Focus()
  135.         End If
  136.  
  137.         Invalidate()
  138.  
  139.     End Sub
  140.  
  141.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  142.         MyBase.OnMouseUp(e)
  143.         formCanMove = False
  144.     End Sub
  145.  
  146. End Class
  147.  
  148. Class ascButton
  149.     Inherits Control
  150.  
  151.     Private _glowColor As Color
  152.     Public Property GlowColor As Color
  153.         Get
  154.             Return _glowColor
  155.         End Get
  156.         Set(ByVal value As Color)
  157.             _glowColor = value
  158.             Invalidate()
  159.         End Set
  160.     End Property
  161.  
  162.     Enum State
  163.         None
  164.         Over
  165.         Down
  166.     End Enum
  167.  
  168.     Private MouseState As State
  169.  
  170.     Sub New()
  171.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  172.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  173.         Size = New Size(100, 40)
  174.         Font = New Font("Arial", 11)
  175.         Cursor = Cursors.Hand
  176.         BackColor = Color.FromArgb(5, 30, 70)
  177.         ForeColor = Color.FromArgb(195, 230, 255)
  178.         GlowColor = Color.FromArgb(40, 95, 210)
  179.     End Sub
  180.  
  181.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  182.         MyBase.OnPaint(e)
  183.  
  184.         Dim G As Graphics = e.Graphics
  185.  
  186.         G.SmoothingMode = SmoothingMode.HighQuality
  187.         G.Clear(Parent.BackColor)
  188.  
  189.         Dim slope As Integer = 5
  190.  
  191.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  192.         Dim mainPath As GraphicsPath = RoundRect(mainRect, slope)
  193.         G.FillPath(New LinearGradientBrush(mainRect, BackColor, Color.FromArgb(25, Color.Black), 90.0F), mainPath)
  194.         G.DrawPath(New Pen(Color.FromArgb(BackColor.R / 2, BackColor.G / 2, BackColor.B / 2)), mainPath)
  195.  
  196.         Dim glow As Integer
  197.         If MouseState = State.Over Then
  198.             glow = 200
  199.         ElseIf MouseState = State.Down Then
  200.             glow = 255
  201.         Else
  202.             glow = 100
  203.         End If
  204.         G.DrawPath(New Pen(Color.FromArgb(glow, _glowColor)), mainPath)
  205.  
  206.         Dim textX As Integer = ((Width - 1) / 2) - (G.MeasureString(Text, Font).Width / 2)
  207.         Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  208.         G.DrawString(Text, Font, New SolidBrush(ForeColor), New Point(textX, textY))
  209.  
  210.     End Sub
  211.  
  212.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  213.         MyBase.OnMouseEnter(e)
  214.         MouseState = State.Over
  215.         Invalidate()
  216.     End Sub
  217.  
  218.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  219.         MyBase.OnMouseLeave(e)
  220.         MouseState = State.None
  221.         Invalidate()
  222.     End Sub
  223.  
  224.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  225.         MyBase.OnMouseUp(e)
  226.         MouseState = State.Over
  227.         Invalidate()
  228.     End Sub
  229.  
  230.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  231.         MyBase.OnMouseDown(e)
  232.         MouseState = State.Down
  233.         Invalidate()
  234.     End Sub
  235.  
  236. End Class
  237.  
  238. Class ascButton_Big
  239.     Inherits Control
  240.  
  241.     Private _glowColor As Color
  242.     Public Property GlowColor As Color
  243.         Get
  244.             Return _glowColor
  245.         End Get
  246.         Set(ByVal value As Color)
  247.             _glowColor = value
  248.             Invalidate()
  249.         End Set
  250.     End Property
  251.  
  252.     Private _image As Image
  253.     Public Property Image As Image
  254.         Get
  255.             Return _image
  256.         End Get
  257.         Set(ByVal value As Image)
  258.             _image = value
  259.             Invalidate()
  260.         End Set
  261.     End Property
  262.  
  263.     Enum State
  264.         None
  265.         Over
  266.         Down
  267.     End Enum
  268.  
  269.     Private MouseState As State
  270.  
  271.     Sub New()
  272.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  273.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  274.         Size = New Size(160, 60)
  275.         Font = New Font("Arial", 11)
  276.         Cursor = Cursors.Hand
  277.         ForeColor = Color.FromArgb(5, 125, 250)
  278.         GlowColor = Color.FromArgb(60, 150, 250)
  279.     End Sub
  280.  
  281.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  282.         MyBase.OnPaint(e)
  283.  
  284.         Dim G As Graphics = e.Graphics
  285.  
  286.         G.SmoothingMode = SmoothingMode.HighQuality
  287.         G.Clear(Parent.BackColor)
  288.  
  289.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  290.         G.FillRectangle(Brushes.Black, mainRect)
  291.         G.DrawRectangle(New Pen(Color.FromArgb(30, 45, 60)), mainRect)
  292.  
  293.         Dim hCB As New ColorBlend(4)
  294.         hCB.Colors(0) = Color.FromArgb(30, 45, 60)
  295.         hCB.Colors(1) = _glowColor
  296.         hCB.Colors(2) = _glowColor
  297.         hCB.Colors(3) = hCB.Colors(0)
  298.         hCB.Positions = New Single() {0.0, 0.35, 0.65, 1.0}
  299.         Dim borderBrush As New LinearGradientBrush(mainRect, Color.Black, Color.Black, 0.0F)
  300.         borderBrush.InterpolationColors = hCB
  301.         G.DrawLine(New Pen(borderBrush), New Point(0, 0), New Point(Width - 1, 0))
  302.         G.DrawLine(New Pen(borderBrush), New Point(0, Height - 1), New Point(Width - 1, Height - 1))
  303.  
  304.         Dim glow As Integer
  305.         If MouseState = State.Over Then
  306.             glow = 20
  307.         ElseIf MouseState = State.Down Then
  308.             glow = 30
  309.         Else
  310.             glow = 0
  311.         End If
  312.         G.FillRectangle(New SolidBrush(Color.FromArgb(glow, Color.WhiteSmoke)), mainRect)
  313.         G.DrawRectangle(New Pen(Color.FromArgb(glow, _glowColor)), mainRect)
  314.  
  315.         Dim textX As Integer
  316.         Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  317.         If Image IsNot Nothing Then
  318.             Dim imageWidth As Integer = Me.Height - 24, imageHeight As Integer = Me.Height - 24
  319.             Dim imageX As Integer = ((Me.Width - 1) / 2) - ((imageWidth + 4 + G.MeasureString(Text, Font).Width) / 2)
  320.             Dim imageY As Integer = ((Me.Height - 1) / 2) - (imageHeight / 2)
  321.             G.DrawImage(_image, imageX, imageY, imageWidth, imageHeight)
  322.             textX = imageX + imageWidth + 4
  323.         Else
  324.             textX = ((Width - 1) / 2) - (G.MeasureString(Text, Font).Width / 2)
  325.         End If
  326.         G.DrawString(Text, Font, New SolidBrush(ForeColor), New Point(textX, textY))
  327.  
  328.     End Sub
  329.  
  330.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  331.         MyBase.OnMouseEnter(e)
  332.         MouseState = State.Over
  333.         Invalidate()
  334.     End Sub
  335.  
  336.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  337.         MyBase.OnMouseLeave(e)
  338.         MouseState = State.None
  339.         Invalidate()
  340.     End Sub
  341.  
  342.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  343.         MyBase.OnMouseUp(e)
  344.         MouseState = State.Over
  345.         Invalidate()
  346.     End Sub
  347.  
  348.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  349.         MyBase.OnMouseDown(e)
  350.         MouseState = State.Down
  351.         Invalidate()
  352.     End Sub
  353.  
  354. End Class
  355.  
  356. Class ascTabControl
  357.     Inherits TabControl
  358.  
  359.     Sub New()
  360.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or _
  361.                  ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
  362.         ItemSize = New Size(0, 34)
  363.         Padding = New Size(24, 0)
  364.         Font = New Font("Arial", 12)
  365.     End Sub
  366.  
  367.     Protected Overrides Sub CreateHandle()
  368.         MyBase.CreateHandle()
  369.         Alignment = TabAlignment.Top
  370.     End Sub
  371.  
  372.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  373.         MyBase.OnPaint(e)
  374.  
  375.         Dim G As Graphics = e.Graphics
  376.  
  377.         G.SmoothingMode = SmoothingMode.HighQuality
  378.         G.Clear(Parent.BackColor)
  379.  
  380.         Dim FontColor As New Color
  381.  
  382.         For i = 0 To TabCount - 1
  383.  
  384.             Dim mainRect As Rectangle = GetTabRect(i)
  385.  
  386.             If i = SelectedIndex Then
  387.                 FontColor = Color.FromArgb(80, 170, 245)
  388.                 G.DrawLine(New Pen(Color.FromArgb(5, 135, 250)), New Point(mainRect.X - 2, mainRect.Height - 1), New Point(mainRect.X + mainRect.Width - 2, mainRect.Height - 1))
  389.                 G.DrawLine(New Pen(Color.FromArgb(25, 100, 140)), New Point(mainRect.X - 2, mainRect.Height), New Point(mainRect.X + mainRect.Width - 2, mainRect.Height))
  390.             Else
  391.                 FontColor = Color.FromArgb(160, 160, 160)
  392.                 G.DrawLine(New Pen(Color.FromArgb(30, 55, 85)), New Point(mainRect.X - 2, mainRect.Height - 1), New Point(mainRect.X + mainRect.Width - 2, mainRect.Height - 1))
  393.                 G.DrawLine(New Pen(Color.FromArgb(30, 55, 85)), New Point(mainRect.X - 2, mainRect.Height), New Point(mainRect.X + mainRect.Width - 2, mainRect.Height))
  394.             End If
  395.  
  396.             If i <> 0 Then
  397.                 G.DrawLine(New Pen(Color.FromArgb(30, 90, 125)), New Point(mainRect.X - 4, mainRect.Height - 7), New Point(mainRect.X + 4, mainRect.Y + 6))
  398.             End If
  399.  
  400.             Dim titleX As Integer = (mainRect.Location.X + mainRect.Width / 2) - (G.MeasureString(TabPages(i).Text, Font).Width / 2)
  401.             Dim titleY As Integer = (mainRect.Location.Y + mainRect.Height / 2) - (G.MeasureString(TabPages(i).Text, Font).Height / 2)
  402.             G.DrawString(TabPages(i).Text, Font, New SolidBrush(FontColor), New Point(titleX, titleY))
  403.  
  404.             Try : TabPages(i).BackColor = Parent.BackColor : Catch : End Try
  405.  
  406.         Next
  407.  
  408.     End Sub
  409.  
  410. End Class
  411.  
  412. Class ascProgressBar
  413.     Inherits Control
  414.  
  415.     Private _Maximum As Integer = 100
  416.     Public Property Maximum As Integer
  417.         Get
  418.             Return _Maximum
  419.         End Get
  420.         Set(ByVal v As Integer)
  421.             If v < 1 Then v = 1
  422.             If v < _Value Then _Value = v
  423.             _Maximum = v
  424.             Invalidate()
  425.         End Set
  426.     End Property
  427.  
  428.     Private _Value As Integer
  429.     Public Property Value As Integer
  430.         Get
  431.             Return _Value
  432.         End Get
  433.         Set(ByVal v As Integer)
  434.             If v > _Maximum Then v = Maximum
  435.             _Value = v
  436.             Invalidate()
  437.         End Set
  438.     End Property
  439.  
  440.     Private _percent As Integer
  441.     Public ReadOnly Property Percent As Integer
  442.         Get
  443.             Return _percent
  444.         End Get
  445.     End Property
  446.  
  447.     Sub New()
  448.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  449.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  450.         Size = New Size(200, 40)
  451.         Font = New Font("Arial", 11)
  452.     End Sub
  453.  
  454.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  455.         MyBase.OnPaint(e)
  456.  
  457.         Dim G As Graphics = e.Graphics
  458.  
  459.         G.SmoothingMode = SmoothingMode.HighQuality
  460.         G.Clear(Parent.BackColor)
  461.  
  462.         Dim slope As Integer = 3
  463.         _percent = (_Value / _Maximum) * 100
  464.  
  465.         Dim midY As Integer = ((Height - 1) / 2)
  466.         Dim mainRect As New Rectangle(12, midY - 4, Width - 25, 7)
  467.         Dim mainPath As GraphicsPath = RoundRect(mainRect, slope)
  468.         Dim barBrush As New LinearGradientBrush(mainRect, Color.FromArgb(32, 32, 32), Color.FromArgb(45, 45, 45), 90.0F)
  469.         G.FillPath(barBrush, mainPath)
  470.  
  471.         Dim barRect As New Rectangle(12, midY - 4, CInt(((Width / _Maximum) * _Value) - ((_percent - 1) / 4)), 7)
  472.         If barRect.Width > 0 Then
  473.             Dim barHorizontal As New LinearGradientBrush(barRect, Color.FromArgb(5, 80, 140), Color.FromArgb(45, 180, 200), 0.0F)
  474.             G.FillPath(barHorizontal, RoundRect(barRect, slope))
  475.  
  476.             Dim vertCB As New ColorBlend(5)
  477.             vertCB.Colors(0) = Color.Transparent
  478.             vertCB.Colors(1) = Color.Transparent
  479.             vertCB.Colors(2) = Color.FromArgb(0, 150, 220)
  480.             vertCB.Colors(3) = Color.Transparent
  481.             vertCB.Colors(4) = Color.Transparent
  482.             vertCB.Positions = New Single() {0.0, 0.4, 0.5, 0.6, 1.0}
  483.             Dim barVertical As New LinearGradientBrush(barRect, Color.Black, Color.Black, 90.0F)
  484.             barVertical.InterpolationColors = vertCB
  485.             G.FillPath(barVertical, RoundRect(barRect, slope))
  486.         End If
  487.  
  488.         If _Value > 0 Then
  489.             Dim bubbleRect As New Rectangle(barRect.Width - 3, 0, midY * 2 - 3, midY * 2)
  490.             Dim bubblePath As GraphicsPath = RoundRect(bubbleRect, midY)
  491.             Dim bubbleBrush As New PathGradientBrush(bubblePath)
  492.             bubbleBrush.CenterColor = Color.FromArgb(230, 245, 255)
  493.             bubbleBrush.SurroundColors = {Color.Transparent}
  494.             G.FillPath(bubbleBrush, bubblePath)
  495.         End If
  496.  
  497.     End Sub
  498. End Class
  499.  
  500. <DefaultEvent("CheckedChanged")> Class ascCheckBox
  501.     Inherits Control
  502.  
  503.     Event CheckedChanged(ByVal sender As Object)
  504.  
  505.     Private _checked As Boolean
  506.     Public Property Checked() As Boolean
  507.         Get
  508.             Return _checked
  509.         End Get
  510.         Set(ByVal value As Boolean)
  511.             _checked = value
  512.             Invalidate()
  513.         End Set
  514.     End Property
  515.  
  516.     Sub New()
  517.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  518.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  519.         Size = New Size(120, 17)
  520.         Font = New Font("Arial", 9)
  521.     End Sub
  522.  
  523.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  524.         MyBase.OnPaint(e)
  525.  
  526.         Dim G As Graphics = e.Graphics
  527.         G.SmoothingMode = SmoothingMode.HighQuality
  528.         G.Clear(Parent.BackColor)
  529.  
  530.         Height = 17
  531.  
  532.         Dim boxRect As New Rectangle(1, 1, Height - 3, Height - 3)
  533.         G.DrawEllipse(New Pen(Color.FromArgb(30, 140, 240), 2), boxRect)
  534.  
  535.         Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  536.         G.DrawString(Text, Font, New SolidBrush(Color.FromArgb(160, 160, 160)), New Point((Height - 1) + 4, textY))
  537.  
  538.         If _checked Then G.DrawString("a", New Font("Marlett", 17), New SolidBrush(Color.FromArgb(120, 180, 255)), New Point(-3, -5))
  539.  
  540.     End Sub
  541.  
  542.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  543.         MyBase.OnMouseDown(e)
  544.  
  545.         If _checked Then
  546.             _checked = False
  547.         Else
  548.             _checked = True
  549.         End If
  550.  
  551.         RaiseEvent CheckedChanged(Me)
  552.         Invalidate()
  553.  
  554.     End Sub
  555.  
  556. End Class
  557.  
  558. <DefaultEvent("CheckedChanged")> Class ascSwitch
  559.     Inherits Control
  560.  
  561.     Event CheckedChanged(ByVal sender As Object)
  562.  
  563.     Private _checked As Boolean
  564.     Public Property Checked() As Boolean
  565.         Get
  566.             Return _checked
  567.         End Get
  568.         Set(ByVal value As Boolean)
  569.             _checked = value
  570.             Invalidate()
  571.         End Set
  572.     End Property
  573.  
  574.     Sub New()
  575.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  576.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  577.         Size = New Size(40, 17)
  578.     End Sub
  579.  
  580.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  581.         MyBase.OnPaint(e)
  582.  
  583.         Dim G As Graphics = e.Graphics
  584.         G.SmoothingMode = SmoothingMode.HighQuality
  585.         G.Clear(Parent.BackColor)
  586.  
  587.         Dim slope As Integer = (Height - 1) / 2
  588.         Height = 17
  589.  
  590.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  591.         Dim mainPath As GraphicsPath = RoundRect(mainRect, slope)
  592.  
  593.         If _checked Then
  594.             Dim bgBrush As New LinearGradientBrush(mainRect, Color.FromArgb(10, 30, 50), Color.FromArgb(5, 80, 140), 90.0F)
  595.             G.FillPath(bgBrush, mainPath)
  596.             Dim switchRect As New Rectangle(Width - 14, 3, 10, 10)
  597.             Dim switchBrush As New LinearGradientBrush(switchRect, Color.FromArgb(100, 220, 250), Color.FromArgb(15, 150, 220), 90.0F)
  598.             G.FillEllipse(switchBrush, switchRect)
  599.             Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString("On", New Font("Arial", 8)).Height / 2) + 1
  600.             G.DrawString("On", New Font("Arial", 8), New SolidBrush(Color.FromArgb(180, 180, 180)), New Point(5, textY))
  601.             G.DrawPath(New Pen(Color.FromArgb(5, 80, 140)), mainPath)
  602.         Else
  603.             Dim bgBrush As New LinearGradientBrush(mainRect, Color.FromArgb(40, 40, 40), Color.FromArgb(80, 80, 80), 90.0F)
  604.             G.FillPath(bgBrush, mainPath)
  605.             Dim switchRect As New Rectangle(3, 3, 10, 10)
  606.             Dim switchBrush As New LinearGradientBrush(switchRect, Color.FromArgb(150, 150, 150), Color.FromArgb(120, 120, 120), 90.0F)
  607.             G.FillEllipse(switchBrush, switchRect)
  608.             Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString("Off", New Font("Arial", 8)).Height / 2) + 1
  609.             G.DrawString("Off", New Font("Arial", 8), New SolidBrush(Color.FromArgb(180, 180, 180)), New Point(15, textY))
  610.             G.DrawPath(New Pen(Color.FromArgb(80, 80, 80)), mainPath)
  611.         End If
  612.  
  613.     End Sub
  614.  
  615.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  616.         MyBase.OnMouseDown(e)
  617.  
  618.         If _checked Then
  619.             _checked = False
  620.         Else
  621.             _checked = True
  622.         End If
  623.  
  624.         RaiseEvent CheckedChanged(Me)
  625.         Invalidate()
  626.  
  627.     End Sub
  628.  
  629. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement