Advertisement
Guest User

Gray/Blue VB.NET Theme

a guest
Dec 20th, 2013
1,626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 28.00 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. Module DesignFunctions
  4.     Function ToBrush(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
  5.         Return ToBrush(Color.FromArgb(A, R, G, B))
  6.     End Function
  7.     Function ToBrush(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
  8.         Return ToBrush(Color.FromArgb(R, G, B))
  9.     End Function
  10.     Function ToBrush(ByVal A As Integer, ByVal C As Color) As Brush
  11.         Return ToBrush(Color.FromArgb(A, C))
  12.     End Function
  13.     Function ToBrush(ByVal Pen As Pen) As Brush
  14.         Return ToBrush(Pen.Color)
  15.     End Function
  16.     Function ToBrush(ByVal Color As Color) As Brush
  17.         Return New SolidBrush(Color)
  18.     End Function
  19.     Function ToPen(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
  20.         Return ToPen(Color.FromArgb(A, R, G, B))
  21.     End Function
  22.     Function ToPen(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
  23.         Return ToPen(Color.FromArgb(R, G, B))
  24.     End Function
  25.     Function ToPen(ByVal A As Integer, ByVal C As Color) As Pen
  26.         Return ToPen(Color.FromArgb(A, C))
  27.     End Function
  28.     Function ToPen(ByVal Color As Color) As Pen
  29.         Return ToPen(New SolidBrush(Color))
  30.     End Function
  31.     Function ToPen(ByVal Brush As SolidBrush) As Pen
  32.         Return New Pen(Brush)
  33.     End Function
  34.  
  35.     Class CornerStyle
  36.         Public TopLeft As Boolean
  37.         Public TopRight As Boolean
  38.         Public BottomLeft As Boolean
  39.         Public BottomRight As Boolean
  40.     End Class
  41.  
  42.     Public Function AdvRect(ByVal Rectangle As Rectangle, ByVal CornerStyle As CornerStyle, ByVal Curve As Integer) As GraphicsPath
  43.         AdvRect = New GraphicsPath()
  44.         Dim ArcRectangleWidth As Integer = Curve * 2
  45.  
  46.         If CornerStyle.TopLeft Then
  47.             AdvRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  48.         Else
  49.             AdvRect.AddLine(Rectangle.X, Rectangle.Y, Rectangle.X + ArcRectangleWidth, Rectangle.Y)
  50.         End If
  51.  
  52.         If CornerStyle.TopRight Then
  53.             AdvRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  54.         Else
  55.             AdvRect.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + ArcRectangleWidth)
  56.         End If
  57.  
  58.         If CornerStyle.BottomRight Then
  59.             AdvRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  60.         Else
  61.             AdvRect.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height, Rectangle.X + Rectangle.Width - ArcRectangleWidth, Rectangle.Y + Rectangle.Height)
  62.         End If
  63.  
  64.         If CornerStyle.BottomLeft Then
  65.             AdvRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  66.         Else
  67.             AdvRect.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y + Rectangle.Height - ArcRectangleWidth)
  68.         End If
  69.  
  70.         AdvRect.CloseAllFigures()
  71.  
  72.         Return AdvRect
  73.     End Function
  74.  
  75.     Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  76.         RoundRect = New GraphicsPath()
  77.         Dim ArcRectangleWidth As Integer = Curve * 2
  78.         RoundRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  79.         RoundRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  80.         RoundRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  81.         RoundRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  82.         RoundRect.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, ArcRectangleWidth + Rectangle.Y))
  83.         RoundRect.CloseAllFigures()
  84.         Return RoundRect
  85.     End Function
  86.  
  87.     Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
  88.         Return RoundRect(New Rectangle(X, Y, Width, Height), Curve)
  89.     End Function
  90.  
  91.     Class PillStyle
  92.         Public Left As Boolean
  93.         Public Right As Boolean
  94.     End Class
  95.  
  96.     Public Function Pill(ByVal Rectangle As Rectangle, ByVal PillStyle As PillStyle) As GraphicsPath
  97.         Pill = New GraphicsPath()
  98.  
  99.         If PillStyle.Left Then
  100.             Pill.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Height, Rectangle.Height), -270, 180)
  101.         Else
  102.             Pill.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y)
  103.         End If
  104.  
  105.         If PillStyle.Right Then
  106.             Pill.AddArc(New Rectangle(Rectangle.X + Rectangle.Width - Rectangle.Height, Rectangle.Y, Rectangle.Height, Rectangle.Height), -90, 180)
  107.         Else
  108.             Pill.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height)
  109.         End If
  110.  
  111.         Pill.CloseAllFigures()
  112.  
  113.         Return Pill
  114.     End Function
  115.  
  116.     Public Function Pill(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal PillStyle As PillStyle)
  117.         Return Pill(New Rectangle(X, Y, Width, Height), PillStyle)
  118.     End Function
  119.  
  120. End Module
  121.  
  122. Public Class GrayCombo
  123.     Inherits ComboBox
  124.  
  125.     Sub New()
  126.         SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  127.                  ControlStyles.OptimizedDoubleBuffer Or _
  128.                  ControlStyles.UserPaint Or _
  129.                  ControlStyles.ResizeRedraw Or _
  130.                  ControlStyles.SupportsTransparentBackColor, True)
  131.     End Sub
  132.  
  133.     Protected Overrides Sub CreateHandle()
  134.         MyBase.CreateHandle()
  135.  
  136.         DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
  137.         DropDownStyle = ComboBoxStyle.DropDownList
  138.         ItemHeight = 20
  139.     End Sub
  140.  
  141.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  142.         MyBase.OnPaint(e)
  143.         Dim G As Graphics = e.Graphics
  144.  
  145.         G.Clear(Parent.BackColor)
  146.  
  147.         Dim BackgroundGradient As LinearGradientBrush = New LinearGradientBrush(New Point(0, 0), New Point(0, Height - 1), Color.FromArgb(75, 130, 195), Color.FromArgb(40, 80, 135))
  148.         G.FillPath(BackgroundGradient, RoundRect(0, 0, Width - 1, Height - 1, 3))
  149.         G.DrawLine(ToPen(100, Color.White), New Point(2, 1), New Point(Width - 2, 1))
  150.         G.DrawPath(Pens.Gray, RoundRect(0, 0, Width - 1, Height - 1, 3))
  151.         G.DrawPath(Pens.Black, RoundRect(0, 0, Width - 1, Height - 2, 3))
  152.         BackgroundGradient.Dispose()
  153.  
  154.         Dim TriangleRectangle As Rectangle = New Rectangle(Width - 16, Height / 2 - 2, 8, 4)
  155.  
  156.         Dim TrianglePoints As New List(Of Point)()
  157.         TrianglePoints.Add(New Point(TriangleRectangle.X, TriangleRectangle.Y))
  158.         TrianglePoints.Add(New Point(TriangleRectangle.X + TriangleRectangle.Width, TriangleRectangle.Y))
  159.         TrianglePoints.Add(New Point(TriangleRectangle.X + TriangleRectangle.Width / 2, TriangleRectangle.Y + TriangleRectangle.Height))
  160.  
  161.         G.FillPolygon(Brushes.White, TrianglePoints.ToArray)
  162.  
  163.         Try
  164.             If Items.Count > 0 Then
  165.                 If Not SelectedIndex = -1 Then
  166.                     G.DrawString(Items(SelectedIndex), Font, Brushes.Black, New Rectangle(5, -1, Width - 20, Height), New StringFormat() With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})
  167.                     G.DrawString(Items(SelectedIndex), Font, Brushes.White, New Rectangle(5, 0, Width - 20, Height), New StringFormat() With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})
  168.                 Else
  169.                     G.DrawString(Items(0), Font, Brushes.Black, New Rectangle(5, -1, Width - 20, Height), New StringFormat() With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})
  170.                     G.DrawString(Items(0), Font, Brushes.White, New Rectangle(5, 0, Width - 20, Height), New StringFormat() With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})
  171.                 End If
  172.             End If
  173.         Catch
  174.             'Something went wrong, so we do nothing.
  175.         End Try
  176.     End Sub
  177.  
  178.  
  179.     Sub ReplaceItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
  180.         e.DrawBackground()
  181.         Dim G As Graphics = e.Graphics
  182.  
  183.         Try
  184.             G.FillRectangle(ToBrush(95, 95, 95), e.Bounds)
  185.             G.DrawString(MyBase.GetItemText(MyBase.Items(e.Index)), e.Font, Brushes.LightGray, New Rectangle(e.Bounds.X + 4, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), New StringFormat With {.LineAlignment = StringAlignment.Center})
  186.  
  187.             If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
  188.                 Dim BackgroundGradient As LinearGradientBrush = New LinearGradientBrush(New Point(e.Bounds.X, e.Bounds.Y), New Point(e.Bounds.X, e.Bounds.Y + e.Bounds.Height - 1), Color.FromArgb(75, 130, 195), Color.FromArgb(40, 80, 135))
  189.                 G.FillPath(BackgroundGradient, RoundRect(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1, 3))
  190.                 G.DrawLine(ToPen(100, Color.White), New Point(e.Bounds.X, e.Bounds.Y + 1), New Point(e.Bounds.Width - 1, e.Bounds.Y + 1))
  191.                 G.DrawPath(Pens.Gray, RoundRect(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1, 3))
  192.                 G.DrawPath(Pens.Black, RoundRect(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 2, 3))
  193.  
  194.                 G.DrawString(MyBase.GetItemText(MyBase.Items(e.Index)), e.Font, Brushes.White, New Rectangle(e.Bounds.X + 4, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), New StringFormat With {.LineAlignment = StringAlignment.Center})
  195.             End If
  196.         Catch
  197.             'Uh oh
  198.         End Try
  199.     End Sub
  200.  
  201.     Protected Overrides Sub OnSelectedItemChanged(ByVal e As System.EventArgs)
  202.         MyBase.OnSelectedItemChanged(e)
  203.  
  204.         Invalidate()
  205.     End Sub
  206. End Class
  207.  
  208.  
  209. Class GrayButton
  210.     Inherits Control
  211.  
  212.     Enum State
  213.         None
  214.         Over
  215.         Down
  216.     End Enum
  217.  
  218.     Private MouseState As State
  219.  
  220.     Sub New()
  221.         SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  222.                  ControlStyles.OptimizedDoubleBuffer Or _
  223.                  ControlStyles.UserPaint Or _
  224.                  ControlStyles.ResizeRedraw, True)
  225.  
  226.         MouseState = State.None
  227.     End Sub
  228.  
  229.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  230.         MyBase.OnPaint(e)
  231.         Dim G As Graphics = e.Graphics
  232.  
  233.         G.Clear(Parent.BackColor)
  234.  
  235.         Dim BackgroundGradient As LinearGradientBrush = New LinearGradientBrush(New Point(0, 0), New Point(0, Height), Color.Transparent, Color.Transparent)
  236.  
  237.         Select Case MouseState
  238.             Case State.None
  239.                 BackgroundGradient.LinearColors = New Color() {Color.FromArgb(127, 127, 127), Color.FromArgb(93, 93, 93)}
  240.             Case State.Over
  241.                 BackgroundGradient.LinearColors = New Color() {Color.FromArgb(75, 130, 195), Color.FromArgb(40, 80, 135)}
  242.             Case State.Down
  243.                 BackgroundGradient.LinearColors = New Color() {Color.FromArgb(55, 110, 175), Color.FromArgb(40, 80, 135)}
  244.         End Select
  245.  
  246.         G.FillPath(BackgroundGradient, RoundRect(0, 0, Width - 1, Height - 1, 3))
  247.         G.DrawLine(ToPen(100, Color.White), New Point(2, 1), New Point(Width - 3, 1))
  248.         G.DrawPath(Pens.Gray, RoundRect(0, 0, Width - 1, Height - 1, 3))
  249.         G.DrawPath(Pens.Black, RoundRect(0, 0, Width - 1, Height - 2, 3))
  250.  
  251.         BackgroundGradient.Dispose()
  252.  
  253.         G.DrawString(Text, New Font(Font.Name, Font.Size, FontStyle.Bold), Brushes.Black, New Rectangle(0, 0, Width - 1, Height - 1), New StringFormat() With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  254.         G.DrawString(Text, New Font(Font.Name, Font.Size, FontStyle.Bold), Brushes.White, New Rectangle(0, 1, Width - 1, Height - 1), New StringFormat() With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  255.     End Sub
  256.  
  257.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  258.         MyBase.OnMouseEnter(e)
  259.         MouseState = State.Over : Invalidate()
  260.     End Sub
  261.  
  262.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  263.         MyBase.OnMouseLeave(e)
  264.         MouseState = State.None : Invalidate()
  265.     End Sub
  266.  
  267.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  268.         MyBase.OnMouseDown(e)
  269.         MouseState = State.Down : Invalidate()
  270.     End Sub
  271.  
  272.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  273.         MyBase.OnMouseUp(e)
  274.         MouseState = State.Over : Invalidate()
  275.     End Sub
  276. End Class
  277.  
  278. Class GrayProgressBar
  279.     Inherits Control
  280.  
  281. #Region " Properties "
  282.  
  283.     Private _minimum As Integer
  284.     Public Property Minimum() As Integer
  285.         Get
  286.             Return _minimum
  287.         End Get
  288.         Set(ByVal value As Integer)
  289.             _minimum = value
  290.  
  291.             If value > _maximum Then _maximum = value
  292.             If value > _value Then _value = value
  293.  
  294.             Invalidate()
  295.         End Set
  296.     End Property
  297.  
  298.     Private _maximum As Integer
  299.     Public Property Maximum() As Integer
  300.         Get
  301.             Return _maximum
  302.         End Get
  303.         Set(ByVal value As Integer)
  304.             _maximum = value
  305.  
  306.             If _maximum < 1 Then _maximum = 1
  307.  
  308.             If value < _minimum Then _minimum = value
  309.             If value < _value Then _value = value
  310.  
  311.             Invalidate()
  312.         End Set
  313.     End Property
  314.  
  315.     Event ValueChanged()
  316.     Private _value As Integer
  317.     Public Property Value() As Integer
  318.         Get
  319.             Return _value
  320.         End Get
  321.         Set(ByVal value As Integer)
  322.             If value < _minimum Then
  323.                 _value = _minimum
  324.             ElseIf value > _maximum Then
  325.                 _value = _maximum
  326.             Else
  327.                 _value = value
  328.             End If
  329.  
  330.             Invalidate()
  331.             RaiseEvent ValueChanged()
  332.         End Set
  333.     End Property
  334.  
  335. #End Region
  336.  
  337.     Sub New()
  338.         SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  339.                  ControlStyles.OptimizedDoubleBuffer Or _
  340.                  ControlStyles.UserPaint Or _
  341.                  ControlStyles.ResizeRedraw, True)
  342.  
  343.         _maximum = 100
  344.         _minimum = 0
  345.         _value = 0
  346.     End Sub
  347.  
  348.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  349.         MyBase.OnPaint(e)
  350.         Dim G As Graphics = e.Graphics
  351.  
  352.         G.Clear(Parent.BackColor)
  353.  
  354.         G.FillPath(ToBrush(85, 85, 85), RoundRect(0, 0, Width - 1, Height - 1, 3))
  355.  
  356.         Dim BackgroundGradient As LinearGradientBrush = New LinearGradientBrush(New Point(0, 0), New Point(0, Height), Color.FromArgb(75, 130, 195), Color.FromArgb(40, 80, 135))
  357.  
  358.         G.FillPath(BackgroundGradient, RoundRect(0, 1, (Width - 1) * _value / _maximum, Height - 3, 3))
  359.         G.DrawPath(ToPen(150, Color.Black), RoundRect(0, 1, (Width - 1) * _value / _maximum, Height - 3, 3))
  360.  
  361.         If _value > 0 Then
  362.             G.SmoothingMode = SmoothingMode.AntiAlias
  363.  
  364.             G.SetClip(RoundRect(0, 0, (Width - 1) * _value / _maximum - 1, Height - 1, 3))
  365.             For i = 0 To (Width - 1) * _value / _maximum Step 25
  366.                 G.DrawLine(New Pen(New SolidBrush(Color.FromArgb(35, Color.White)), 10), New Point(i, 0 - 5), New Point(i + 25, Height + 10))
  367.             Next
  368.             G.ResetClip()
  369.  
  370.             G.DrawLine(ToPen(100, Color.White), New Point(2, 1), New Point((Width - 3) * _value / _maximum - 3, 1))
  371.  
  372.             G.SmoothingMode = SmoothingMode.None
  373.         End If
  374.  
  375.         G.DrawPath(Pens.Gray, RoundRect(0, 0, Width - 1, Height - 1, 3))
  376.         G.DrawPath(Pens.Black, RoundRect(0, 0, Width - 1, Height - 2, 3))
  377.     End Sub
  378. End Class
  379.  
  380. Class GrayRadioButton
  381.     Inherits Control
  382.  
  383.     Event CheckedChanged()
  384.     Private _checked As Boolean
  385.     Public Property Checked() As Boolean
  386.         Get
  387.             Return _checked
  388.         End Get
  389.         Set(ByVal value As Boolean)
  390.             _checked = value
  391.  
  392.             Invalidate()
  393.             RaiseEvent CheckedChanged()
  394.         End Set
  395.     End Property
  396.  
  397.     Enum State
  398.         None
  399.         Over
  400.     End Enum
  401.  
  402.     Private MouseState As State
  403.  
  404.     Sub New()
  405.         SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  406.                  ControlStyles.OptimizedDoubleBuffer Or _
  407.                  ControlStyles.UserPaint Or _
  408.                  ControlStyles.ResizeRedraw, True)
  409.  
  410.         Checked = False
  411.         Size = New Size(15, 15)
  412.         MouseState = State.None
  413.     End Sub
  414.  
  415.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  416.         MyBase.OnPaint(e)
  417.         Dim G As Graphics = e.Graphics
  418.  
  419.         G.SmoothingMode = SmoothingMode.AntiAlias
  420.  
  421.         If Checked Then
  422.             G.FillEllipse(New LinearGradientBrush(New Point(Height / 2, 0), New Point(Height / 2, Height), Color.FromArgb(75, 130, 195), Color.FromArgb(40, 80, 135)), New Rectangle(0, 0, Height - 1, Height - 1))
  423.             G.FillEllipse(ToBrush(150, Color.Black), New Rectangle(4, 4, Height - 9, Height - 9))
  424.         Else
  425.             If MouseState = State.Over Then
  426.                 G.FillEllipse(New LinearGradientBrush(New Point(Height / 2, 0), New Point(Height / 2, Height), Color.FromArgb(75, 130, 195), Color.FromArgb(40, 80, 135)), New Rectangle(0, 0, Height - 1, Height - 1))
  427.             Else
  428.                 G.FillEllipse(New LinearGradientBrush(New Point(Height / 2, 0), New Point(Height / 2, Height), Color.FromArgb(127, 127, 127), Color.FromArgb(93, 93, 93)), New Rectangle(0, 0, Height - 1, Height - 1))
  429.             End If
  430.         End If
  431.  
  432.         G.DrawEllipse(ToPen(50, Color.White), New Rectangle(0, 1, Height - 1, Height - 2))
  433.         G.DrawEllipse(Pens.Black, New Rectangle(0, 0, Height - 1, Height - 1))
  434.     End Sub
  435.  
  436.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
  437.         MyBase.OnClick(e)
  438.  
  439.         If Not Checked Then Checked = True
  440.  
  441.         For Each ctl As Control In Parent.Controls
  442.             If TypeOf ctl Is GrayRadioButton Then
  443.                 If ctl.Handle = Me.Handle Then Continue For
  444.                 If ctl.Enabled Then DirectCast(ctl, GrayRadioButton).Checked = False
  445.             End If
  446.         Next
  447.     End Sub
  448.  
  449.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  450.         MyBase.OnMouseEnter(e)
  451.         MouseState = State.Over : Invalidate()
  452.     End Sub
  453.  
  454.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  455.         MyBase.OnMouseLeave(e)
  456.         MouseState = State.None : Invalidate()
  457.     End Sub
  458. End Class
  459.  
  460. Class GrayContainer
  461.     Inherits ContainerControl
  462.  
  463.     Sub New()
  464.         SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  465.          ControlStyles.OptimizedDoubleBuffer Or _
  466.          ControlStyles.UserPaint Or _
  467.          ControlStyles.ResizeRedraw, True)
  468.     End Sub
  469.  
  470.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  471.         MyBase.OnPaint(e)
  472.         Dim G As Graphics = e.Graphics
  473.  
  474.         G.Clear(Parent.BackColor)
  475.  
  476.         G.SmoothingMode = SmoothingMode.AntiAlias
  477.  
  478.         G.FillPath(ToBrush(10, Color.Black), RoundRect(0, 0, Width - 1, Height - 2, 5))
  479.         G.DrawPath(ToPen(50, Color.White), RoundRect(-1, -4, Width + 1, Height + 3, 5))
  480.         G.DrawPath(ToPen(50, Color.Black), RoundRect(0, 0, Width - 1, Height - 2, 5))
  481.  
  482.         For i = 0 To 10
  483.             G.DrawPath(ToPen(50 / (i + 1), Color.Black), RoundRect(i, i, Width - 1 - (i * 2), Height - 2 - (i * 2), 5))
  484.         Next
  485.     End Sub
  486. End Class
  487.  
  488.  
  489. Class GrayForm
  490.     Inherits ContainerControl
  491.  
  492.     Sub New()
  493.         SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  494.                 ControlStyles.OptimizedDoubleBuffer Or _
  495.                 ControlStyles.UserPaint Or _
  496.                 ControlStyles.ResizeRedraw, True)
  497.  
  498.         Dock = DockStyle.Fill
  499.         BackColor = Color.FromArgb(108, 108, 108)
  500.         ForeColor = Color.White
  501.     End Sub
  502.  
  503.     Protected Overrides Sub CreateHandle()
  504.         MyBase.CreateHandle() : SendToBack()
  505.         Parent.FindForm.TransparencyKey = Color.Fuchsia
  506.         Parent.FindForm.FormBorderStyle = FormBorderStyle.None
  507.     End Sub
  508.  
  509.     Private _ico As Icon
  510.     Public Property Icon() As Icon
  511.         Get
  512.             Return _ico
  513.         End Get
  514.         Set(ByVal value As Icon)
  515.             _ico = value
  516.             Invalidate()
  517.         End Set
  518.     End Property
  519.  
  520. #Region " Movement and Control Buttons"
  521.     Private Cap As Boolean = False
  522.     Private CapL As Point = Nothing
  523.  
  524.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  525.         MyBase.OnMouseDown(e)
  526.         If New Rectangle(0, 0, Width - 40, 25).Contains(e.Location) Then
  527.             Cap = True : CapL = e.Location : End If
  528.         Invalidate()
  529.     End Sub
  530.  
  531.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  532.         MyBase.OnMouseUp(e) : Cap = False
  533.         Invalidate()
  534.     End Sub
  535.  
  536.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  537.         MyBase.OnMouseMove(e) : If Cap Then Parent.Location = MousePosition - CapL
  538.         Invalidate()
  539.     End Sub
  540.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
  541.         MyBase.OnClick(e)
  542.         If New Rectangle(Width - 20, 5, 10, 10).Contains(PointToClient(MousePosition)) Then
  543.             Application.Exit()
  544.         End If
  545.     End Sub
  546. #End Region
  547.  
  548.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  549.         MyBase.OnPaint(e) : Dim G As Graphics = e.Graphics
  550.         G.Clear(BackColor)
  551.  
  552.         'Border
  553.         G.DrawRectangle(Pens.DimGray, New Rectangle(1, 1, Width - 3, Height - 3))
  554.         G.DrawPath(Pens.Black, RoundRect(0, 0, Width - 1, Height - 1, 2))
  555.  
  556.         'Title
  557.         G.FillRectangle(ToBrush(78, 78, 78), New Rectangle(1, 1, Width - 2, 19))
  558.         G.FillRectangle(ToBrush(20, Color.White), New Rectangle(1, 1, Width - 2, 10))
  559.  
  560.         G.DrawLine(ToPen(150, Color.Black), New Point(1, 19), New Point(Width - 2, 19))
  561.         G.DrawLine(ToPen(50, Color.White), New Point(1, 20), New Point(Width - 2, 20))
  562.  
  563.         'Title Icon
  564.         Try
  565.             G.DrawIcon(_ico, New Rectangle(3, 3, 16, 16))
  566.         Catch : End Try
  567.  
  568.         'Title Text
  569.         G.DrawString(Text, Font, ToBrush(120, Color.Black), New Rectangle(1, 0, Width - 2, 19), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  570.         G.DrawString(Text, Font, ToBrush(ForeColor), New Rectangle(1, 1, Width - 2, 19), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  571.  
  572.         Try
  573.             G.DrawRectangle(ToPen(Parent.FindForm.TransparencyKey), New Rectangle(0, 0, 1, 1))
  574.             G.DrawRectangle(ToPen(Parent.FindForm.TransparencyKey), New Rectangle(Width - 1, 0, 1, 1))
  575.             G.DrawRectangle(ToPen(Parent.FindForm.TransparencyKey), New Rectangle(0, Height - 1, 1, 1))
  576.             G.DrawRectangle(ToPen(Parent.FindForm.TransparencyKey), New Rectangle(Width - 1, Height - 1, 1, 1))
  577.         Catch : End Try
  578.  
  579.         G.SmoothingMode = SmoothingMode.AntiAlias
  580.         If New Rectangle(Width - 20, 5, 10, 10).Contains(PointToClient(MousePosition)) Then
  581.             G.DrawLine(New Pen(Brushes.White, 2), New Point(Width - 20, 7), New Point(Width - 13, 13))
  582.             G.DrawLine(New Pen(Brushes.White, 2), New Point(Width - 20, 13), New Point(Width - 13, 7))
  583.             If MouseButtons = Windows.Forms.MouseButtons.Left Then
  584.                 G.DrawLine(New Pen(Brushes.DarkGray, 2), New Point(Width - 20, 7), New Point(Width - 13, 13))
  585.                 G.DrawLine(New Pen(Brushes.DarkGray, 2), New Point(Width - 20, 13), New Point(Width - 13, 7))
  586.             End If
  587.         Else
  588.             G.DrawLine(New Pen(Brushes.Gray, 2), New Point(Width - 20, 7), New Point(Width - 13, 13))
  589.             G.DrawLine(New Pen(Brushes.Gray, 2), New Point(Width - 20, 13), New Point(Width - 13, 7))
  590.         End If
  591.     End Sub
  592. End Class
  593.  
  594. Class GrayCheck
  595.     Inherits Control
  596.  
  597. #Region " Properties "
  598.  
  599.     Event CheckChanged()
  600.     Private _checked As Boolean
  601.     Public Property Checked() As Boolean
  602.         Get
  603.             Return _checked
  604.         End Get
  605.         Set(ByVal value As Boolean)
  606.             _checked = value
  607.  
  608.             Invalidate()
  609.             RaiseEvent CheckChanged()
  610.         End Set
  611.     End Property
  612.  
  613. #End Region
  614.  
  615.     Enum State
  616.         None
  617.         Over
  618.         Down
  619.     End Enum
  620.  
  621.     Private MouseState As State
  622.  
  623.     Sub New()
  624.         SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  625.                 ControlStyles.OptimizedDoubleBuffer Or _
  626.                 ControlStyles.UserPaint Or _
  627.                 ControlStyles.ResizeRedraw, True)
  628.  
  629.         MouseState = State.None
  630.         Size = New Size(15, 15)
  631.     End Sub
  632.  
  633.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  634.         MyBase.OnPaint(e)
  635.         Dim G As Graphics = e.Graphics
  636.  
  637.         G.Clear(Parent.BackColor)
  638.  
  639.         Dim BackgroundGradient As LinearGradientBrush = New LinearGradientBrush(New Point(0, 0), New Point(0, Height), Color.Transparent, Color.Transparent)
  640.  
  641.  
  642.         Select Case MouseState
  643.             Case State.None
  644.                 If Checked Then
  645.                     BackgroundGradient.LinearColors = New Color() {Color.FromArgb(75, 130, 195), Color.FromArgb(40, 80, 135)}
  646.                 Else
  647.                     BackgroundGradient.LinearColors = New Color() {Color.FromArgb(127, 127, 127), Color.FromArgb(93, 93, 93)}
  648.                 End If
  649.             Case State.Over
  650.                 BackgroundGradient.LinearColors = New Color() {Color.FromArgb(75, 130, 195), Color.FromArgb(40, 80, 135)}
  651.             Case State.Down
  652.                 BackgroundGradient.LinearColors = New Color() {Color.FromArgb(55, 110, 175), Color.FromArgb(40, 80, 135)}
  653.         End Select
  654.  
  655.         G.FillPath(BackgroundGradient, RoundRect(0, 0, Width - 1, Height - 1, 2))
  656.  
  657.         G.SmoothingMode = SmoothingMode.AntiAlias
  658.  
  659.         If Checked Then
  660.             Dim c As Rectangle = New Rectangle(3, 2, Width - 7, Height - 7)
  661.             G.DrawLine(New Pen(Brushes.Black, 2), New Point(c.X, c.Y + c.Height / 2), New Point(c.X + c.Width / 2, c.Y + c.Height))
  662.             G.DrawLine(New Pen(Brushes.Black, 2), New Point(c.X + c.Width / 2, c.Y + c.Height), New Point(c.X + c.Width, c.Y))
  663.         End If
  664.  
  665.         G.SmoothingMode = SmoothingMode.None
  666.  
  667.         G.DrawLine(ToPen(100, Color.White), New Point(2, 1), New Point(Width - 3, 1))
  668.         G.DrawPath(Pens.Gray, RoundRect(0, 0, Width - 1, Height - 1, 2))
  669.         G.DrawPath(Pens.Black, RoundRect(0, 0, Width - 1, Height - 2, 2))
  670.  
  671.         BackgroundGradient.Dispose()
  672.     End Sub
  673.  
  674.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  675.         MyBase.OnMouseEnter(e) : MouseState = State.Over : Invalidate()
  676.     End Sub
  677.  
  678.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  679.         MyBase.OnMouseLeave(e) : MouseState = State.None : Invalidate()
  680.     End Sub
  681.  
  682.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  683.         MyBase.OnMouseDown(e) : MouseState = State.Down : Invalidate()
  684.     End Sub
  685.  
  686.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  687.         MyBase.OnMouseUp(e) : MouseState = State.Over : Invalidate()
  688.     End Sub
  689.  
  690.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
  691.         MyBase.OnClick(e)
  692.  
  693.         Checked = Not Checked
  694.     End Sub
  695. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement