Advertisement
xZ3ROxPROJ3CTx

³teen Theme [VB.net]

Nov 2nd, 2012
13,551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 30.57 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Imports System.ComponentModel
  3.  
  4. Public Class ThirteenForm : Inherits ContainerControl
  5.     Enum ColorSchemes
  6.         Light
  7.         Dark
  8.     End Enum
  9.     Event ColorSchemeChanged()
  10.     Private _ColorScheme As ColorSchemes
  11.     Public Property ColorScheme() As ColorSchemes
  12.         Get
  13.             Return _ColorScheme
  14.         End Get
  15.         Set(ByVal value As ColorSchemes)
  16.             _ColorScheme = value
  17.             RaiseEvent ColorSchemeChanged()
  18.         End Set
  19.     End Property
  20.     Protected Sub OnColorSchemeChanged() Handles Me.ColorSchemeChanged
  21.         Invalidate()
  22.         Select Case ColorScheme
  23.             Case ColorSchemes.Dark
  24.                 BackColor = Color.FromArgb(50, 50, 50)
  25.                 ForeColor = Color.White
  26.             Case ColorSchemes.Light
  27.                 BackColor = Color.White
  28.                 ForeColor = Color.Black
  29.         End Select
  30.     End Sub
  31. #Region " Properties "
  32.     Private _AccentColor As Color
  33.     Public Property AccentColor() As Color
  34.         Get
  35.             Return _AccentColor
  36.         End Get
  37.         Set(ByVal value As Color)
  38.             _AccentColor = value
  39.             OnAccentColorChanged()
  40.         End Set
  41.     End Property
  42. #End Region
  43. #Region " Constructor "
  44.     Sub New()
  45.         MyBase.New()
  46.         DoubleBuffered = True
  47.         Font = New Font("Segoe UI Semilight", 9.75F)
  48.         'AccentColor = Color.FromArgb(150, 0, 150)
  49.         AccentColor = Color.DodgerBlue
  50.         ColorScheme = ColorSchemes.Dark
  51.         ForeColor = Color.White
  52.         BackColor = Color.FromArgb(50, 50, 50)
  53.         MoveHeight = 32
  54.     End Sub
  55. #End Region
  56. #Region " Events "
  57.     Event AccentColorChanged()
  58. #End Region
  59. #Region " Overrides "
  60.     Private MouseP As Point = New Point(0, 0)
  61.     Private Cap As Boolean = False
  62.     Private MoveHeight As Integer
  63.     Private pos As Integer = 0
  64.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  65.         MyBase.OnMouseDown(e)
  66.         If e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(0, 0, Width, MoveHeight).Contains(e.Location) Then
  67.             Cap = True : MouseP = e.Location
  68.         End If
  69.     End Sub
  70.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  71.         MyBase.OnMouseMove(e)
  72.         If Cap Then
  73.             Parent.Location = MousePosition - MouseP
  74.         End If
  75.     End Sub
  76.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  77.         MyBase.OnMouseUp(e) : Cap = False
  78.     End Sub
  79.     Protected Overrides Sub OnCreateControl()
  80.         MyBase.OnCreateControl()
  81.         Dock = DockStyle.Fill
  82.         Parent.FindForm().FormBorderStyle = FormBorderStyle.None
  83.     End Sub
  84.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  85.         Dim B As Bitmap = New Bitmap(Width, Height)
  86.         Dim G As Graphics = Graphics.FromImage(B)
  87.         MyBase.OnPaint(e)
  88.  
  89.         G.Clear(BackColor)
  90.         G.DrawLine(New Pen(_AccentColor, 2), New Point(0, 30), New Point(Width, 30))
  91.         G.DrawString(Text, Font, New SolidBrush(ForeColor), New Rectangle(8, 6, Width - 1, Height - 1), StringFormat.GenericDefault)
  92.         G.DrawLine(New Pen(_AccentColor, 3), New Point(8, 27), New Point(8 + G.MeasureString(Text, Font).Width, 27))
  93.  
  94.         G.DrawRectangle(New Pen(Color.FromArgb(100, 100, 100)), New Rectangle(0, 0, Width - 1, Height - 1))
  95.  
  96.         e.Graphics.DrawImage(B, New Point(0, 0))
  97.         G.Dispose() : B.Dispose()
  98.     End Sub
  99.     Protected Sub OnAccentColorChanged() Handles Me.AccentColorChanged
  100.         Invalidate()
  101.     End Sub
  102.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  103.         MyBase.OnTextChanged(e)
  104.         Invalidate()
  105.     End Sub
  106.     Protected Overrides Sub OnResize(e As EventArgs)
  107.         MyBase.OnResize(e)
  108.         Invalidate()
  109.     End Sub
  110. #End Region
  111.  
  112. End Class
  113.  
  114. Public Class ThirteenControlBox : Inherits Control
  115.     Enum ColorSchemes
  116.         Light
  117.         Dark
  118.     End Enum
  119.     Event ColorSchemeChanged()
  120.     Private _ColorScheme As ColorSchemes
  121.     Public Property ColorScheme() As ColorSchemes
  122.         Get
  123.             Return _ColorScheme
  124.         End Get
  125.         Set(ByVal value As ColorSchemes)
  126.             _ColorScheme = value
  127.             RaiseEvent ColorSchemeChanged()
  128.         End Set
  129.     End Property
  130.     Protected Sub OnColorSchemeChanged() Handles Me.ColorSchemeChanged
  131.         Invalidate()
  132.         Select Case ColorScheme
  133.             Case ColorSchemes.Dark
  134.                 BackColor = Color.FromArgb(50, 50, 50)
  135.                 ForeColor = Color.White
  136.             Case ColorSchemes.Light
  137.                 BackColor = Color.White
  138.                 ForeColor = Color.Black
  139.         End Select
  140.     End Sub
  141.     Private _AccentColor As Color
  142.     Public Property AccentColor() As Color
  143.         Get
  144.             Return _AccentColor
  145.         End Get
  146.         Set(ByVal value As Color)
  147.             _AccentColor = value
  148.             Invalidate()
  149.         End Set
  150.     End Property
  151.  
  152.     Sub New()
  153.         MyBase.New()
  154.         DoubleBuffered = True
  155.         SetStyle(ControlStyles.AllPaintingInWmPaint, True)
  156.         SetStyle(ControlStyles.UserPaint, True)
  157.         SetStyle(ControlStyles.ResizeRedraw, True)
  158.         SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
  159.         ForeColor = Color.White
  160.         BackColor = Color.FromArgb(50, 50, 50)
  161.         AccentColor = Color.DodgerBlue
  162.         ColorScheme = ColorSchemes.Dark
  163.         Anchor = AnchorStyles.Top Or AnchorStyles.Right
  164.     End Sub
  165.     Protected Overrides Sub OnResize(e As EventArgs)
  166.         MyBase.OnResize(e)
  167.         Size = New Size(100, 25)
  168.     End Sub
  169.     Enum ButtonHover
  170.         Minimize
  171.         Maximize
  172.         Close
  173.         None
  174.     End Enum
  175.     Dim ButtonState As ButtonHover = ButtonHover.None
  176.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  177.         MyBase.OnMouseMove(e)
  178.         Dim X As Integer = e.Location.X
  179.         Dim Y As Integer = e.Location.Y
  180.         If Y > 0 AndAlso Y < (Height - 2) Then
  181.             If X > 0 AndAlso X < 34 Then
  182.                 ButtonState = ButtonHover.Minimize
  183.             ElseIf X > 33 AndAlso X < 65 Then
  184.                 ButtonState = ButtonHover.Maximize
  185.             ElseIf X > 64 AndAlso X < Width Then
  186.                 ButtonState = ButtonHover.Close
  187.             Else
  188.                 ButtonState = ButtonHover.None
  189.             End If
  190.         Else
  191.             ButtonState = ButtonHover.None
  192.         End If
  193.         Invalidate()
  194.     End Sub
  195.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  196.         Dim B As New Bitmap(Width, Height)
  197.         Dim G As Graphics = Graphics.FromImage(B)
  198.         MyBase.OnPaint(e)
  199.  
  200.         G.Clear(BackColor)
  201.         Select Case ButtonState
  202.             Case ButtonHover.None
  203.                 G.Clear(BackColor)
  204.             Case ButtonHover.Minimize
  205.                 G.FillRectangle(New SolidBrush(_AccentColor), New Rectangle(3, 0, 30, Height))
  206.             Case ButtonHover.Maximize
  207.                 G.FillRectangle(New SolidBrush(_AccentColor), New Rectangle(34, 0, 30, Height))
  208.             Case ButtonHover.Close
  209.                 G.FillRectangle(New SolidBrush(_AccentColor), New Rectangle(65, 0, 35, Height))
  210.         End Select
  211.  
  212.         Dim ButtonFont As New Font("Marlett", 9.75F)
  213.         'Close
  214.         G.DrawString("r", ButtonFont, New SolidBrush(Color.FromArgb(200, 200, 200)), New Point(Width - 16, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  215.         'Maximize
  216.         Select Case Parent.FindForm().WindowState
  217.             Case FormWindowState.Maximized
  218.                 G.DrawString("2", ButtonFont, New SolidBrush(Color.FromArgb(200, 200, 200)), New Point(51, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  219.             Case FormWindowState.Normal
  220.                 G.DrawString("1", ButtonFont, New SolidBrush(Color.FromArgb(200, 200, 200)), New Point(51, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  221.         End Select
  222.         'Minimize
  223.         G.DrawString("0", ButtonFont, New SolidBrush(Color.FromArgb(200, 200, 200)), New Point(20, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  224.  
  225.  
  226.         e.Graphics.DrawImage(B, New Point(0, 0))
  227.         G.Dispose() : B.Dispose()
  228.     End Sub
  229.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  230.         MyBase.OnMouseDown(e)
  231.         Select Case ButtonState
  232.             Case ButtonHover.Close
  233.                 Parent.FindForm().Close()
  234.             Case ButtonHover.Minimize
  235.                 Parent.FindForm().WindowState = FormWindowState.Minimized
  236.             Case ButtonHover.Maximize
  237.                 If Parent.FindForm().WindowState = FormWindowState.Normal Then
  238.                     Parent.FindForm().WindowState = FormWindowState.Maximized
  239.                 Else
  240.                     Parent.FindForm().WindowState = FormWindowState.Normal
  241.                 End If
  242.  
  243.         End Select
  244.     End Sub
  245.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  246.         MyBase.OnMouseLeave(e)
  247.         ButtonState = ButtonHover.None : Invalidate()
  248.     End Sub
  249. End Class
  250. Public Class ThirteenButton : Inherits Button
  251.     Enum MouseState
  252.         None
  253.         Over
  254.         Down
  255.     End Enum
  256.     Enum ColorSchemes
  257.         Light
  258.         Dark
  259.     End Enum
  260.     Private _ColorScheme As ColorSchemes
  261.     Public Property ColorScheme() As ColorSchemes
  262.         Get
  263.             Return _ColorScheme
  264.         End Get
  265.         Set(ByVal value As ColorSchemes)
  266.             _ColorScheme = value
  267.             Invalidate()
  268.         End Set
  269.     End Property
  270.  
  271.     Dim State As MouseState = MouseState.None
  272.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  273.         MyBase.OnMouseEnter(e)
  274.         State = MouseState.Over : Invalidate()
  275.     End Sub
  276.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  277.         MyBase.OnMouseLeave(e)
  278.         State = MouseState.None : Invalidate()
  279.     End Sub
  280.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  281.         MyBase.OnMouseDown(e)
  282.         State = MouseState.Down : Invalidate()
  283.     End Sub
  284.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  285.         MyBase.OnMouseUp(e)
  286.         State = MouseState.Over : Invalidate()
  287.     End Sub
  288.  
  289.     Private _AccentColor As Color
  290.     Public Property AccentColor() As Color
  291.         Get
  292.             Return _AccentColor
  293.         End Get
  294.         Set(ByVal value As Color)
  295.             _AccentColor = value
  296.             OnAccentColorChanged()
  297.         End Set
  298.     End Property
  299.  
  300.     Event AccentColorChanged()
  301.  
  302.     Sub New()
  303.         MyBase.New()
  304.         Font = New Font("Segoe UI Semilight", 9.75F)
  305.         ForeColor = Color.White
  306.         BackColor = Color.FromArgb(50, 50, 50)
  307.         AccentColor = Color.DodgerBlue
  308.         ColorScheme = ColorSchemes.Dark
  309.     End Sub
  310.  
  311.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  312.         Dim B As New Bitmap(Width, Height)
  313.         Dim G As Graphics = Graphics.FromImage(B)
  314.         MyBase.OnPaint(e)
  315.         Dim BGColor As Color
  316.         Select Case ColorScheme
  317.             Case ColorSchemes.Dark
  318.                 BGColor = Color.FromArgb(50, 50, 50)
  319.             Case ColorSchemes.Light
  320.                 BGColor = Color.White
  321.         End Select
  322.  
  323.         Select Case State
  324.             Case MouseState.None
  325.                 G.Clear(BGColor)
  326.             Case MouseState.Over
  327.                 G.Clear(AccentColor)
  328.             Case MouseState.Down
  329.                 G.Clear(AccentColor)
  330.                 G.FillRectangle(New SolidBrush(Color.FromArgb(50, Color.Black)), New Rectangle(0, 0, Width - 1, Height - 1))
  331.         End Select
  332.  
  333.  
  334.         G.DrawRectangle(New Pen(Color.FromArgb(100, 100, 100)), New Rectangle(0, 0, Width - 1, Height - 1))
  335.  
  336.         Dim ButtonString As New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
  337.         Select Case ColorScheme
  338.             Case ColorSchemes.Dark
  339.                 G.DrawString(Text, Font, Brushes.White, New Rectangle(0, 0, Width - 1, Height - 1), ButtonString)
  340.             Case ColorSchemes.Light
  341.                 G.DrawString(Text, Font, Brushes.Black, New Rectangle(0, 0, Width - 1, Height - 1), ButtonString)
  342.         End Select
  343.  
  344.         e.Graphics.DrawImage(B, New Point(0, 0))
  345.         G.Dispose() : B.Dispose()
  346.     End Sub
  347.     Protected Sub OnAccentColorChanged() Handles Me.AccentColorChanged
  348.         Invalidate()
  349.     End Sub
  350. End Class
  351.  
  352. Public Class ThirteenTextBox : Inherits TextBox
  353.     Enum ColorSchemes
  354.         Light
  355.         Dark
  356.     End Enum
  357.     Event ColorSchemeChanged()
  358.     Private _ColorScheme As ColorSchemes
  359.     Public Property ColorScheme() As ColorSchemes
  360.         Get
  361.             Return _ColorScheme
  362.         End Get
  363.         Set(ByVal value As ColorSchemes)
  364.             _ColorScheme = value
  365.             RaiseEvent ColorSchemeChanged()
  366.         End Set
  367.     End Property
  368.  
  369.     Sub New()
  370.         BorderStyle = Windows.Forms.BorderStyle.FixedSingle
  371.         Font = New Font("Segoe UI Semilight", 9.75F)
  372.         BackColor = Color.FromArgb(35, 35, 35)
  373.         ForeColor = Color.White
  374.         ColorScheme = ColorSchemes.Dark
  375.     End Sub
  376.  
  377.     Protected Sub OnColorSchemeChanged() Handles Me.ColorSchemeChanged
  378.         Invalidate()
  379.         Select Case ColorScheme
  380.             Case ColorSchemes.Dark
  381.                 BackColor = Color.FromArgb(35, 35, 35)
  382.                 ForeColor = Color.White
  383.             Case ColorSchemes.Light
  384.                 BackColor = Color.White
  385.                 ForeColor = Color.Black
  386.         End Select
  387.     End Sub
  388. End Class
  389.  
  390. Public Class ThirteenTabControl : Inherits TabControl
  391.     Private _AccentColor As Color
  392.     Public Property AccentColor() As Color
  393.         Get
  394.             Return _AccentColor
  395.         End Get
  396.         Set(ByVal value As Color)
  397.             _AccentColor = value
  398.             Invalidate()
  399.         End Set
  400.     End Property
  401.  
  402.     Private MainColor As Color
  403.     Private ClearColor As Color
  404.     Enum ColorSchemes
  405.         Light
  406.         Dark
  407.     End Enum
  408.     Event ColorSchemeChanged()
  409.     Private _ColorScheme As ColorSchemes
  410.     Public Property ColorScheme() As ColorSchemes
  411.         Get
  412.             Return _ColorScheme
  413.         End Get
  414.         Set(ByVal value As ColorSchemes)
  415.             _ColorScheme = value
  416.             RaiseEvent ColorSchemeChanged()
  417.         End Set
  418.     End Property
  419.     Protected Sub OnColorSchemeChanged() Handles Me.ColorSchemeChanged
  420.         Invalidate()
  421.         Select Case ColorScheme
  422.             Case ColorSchemes.Dark
  423.                 ClearColor = Color.FromArgb(50, 50, 50)
  424.                 MainColor = Color.FromArgb(35, 35, 35)
  425.                 ForeColor = Color.White
  426.             Case ColorSchemes.Light
  427.                 ClearColor = Color.White
  428.                 MainColor = Color.FromArgb(200, 200, 200)
  429.                 ForeColor = Color.Black
  430.         End Select
  431.     End Sub
  432.     Sub New()
  433.         MyBase.New()
  434.         SetStyle(ControlStyles.AllPaintingInWmPaint, True)
  435.         SetStyle(ControlStyles.ResizeRedraw, True)
  436.         SetStyle(ControlStyles.UserPaint, True)
  437.         SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
  438.         DoubleBuffered = True
  439.  
  440.         BackColor = Color.FromArgb(50, 50, 50)
  441.         ForeColor = Color.White
  442.         AccentColor = Color.DodgerBlue
  443.     End Sub
  444.  
  445.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  446.         Dim B As New Bitmap(Width, Height)
  447.         Dim G As Graphics = Graphics.FromImage(B)
  448.         MyBase.OnPaint(e)
  449.  
  450.         Try : SelectedTab.BackColor = MainColor : Catch : End Try
  451.         G.Clear(ClearColor)
  452.  
  453.         For i As Integer = 0 To TabPages.Count - 1
  454.             'If Not i = SelectedIndex Then
  455.             Dim TabRect As New Rectangle(GetTabRect(i).X, GetTabRect(i).Y + 3, GetTabRect(i).Width + 2, GetTabRect(i).Height)
  456.             G.FillRectangle(New SolidBrush(MainColor), TabRect)
  457.             G.DrawString(TabPages(i).Text, New Font("Segoe UI Semilight", 9.75F), New SolidBrush(ForeColor), TabRect, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  458.             'End If
  459.         Next
  460.  
  461.         G.FillRectangle(New SolidBrush(MainColor), 0, ItemSize.Height, Width, Height)
  462.  
  463.         If Not SelectedIndex = -1 Then
  464.             Dim TabRect As New Rectangle(GetTabRect(SelectedIndex).X - 2, GetTabRect(SelectedIndex).Y, GetTabRect(SelectedIndex).Width + 4, GetTabRect(SelectedIndex).Height)
  465.             G.FillRectangle(New SolidBrush(AccentColor), TabRect)
  466.             G.DrawString(TabPages(SelectedIndex).Text, New Font("Segoe UI Semilight", 9.75F), New SolidBrush(ForeColor), TabRect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  467.         End If
  468.  
  469.         e.Graphics.DrawImage(B, New Point(0, 0))
  470.         G.Dispose() : B.Dispose()
  471.     End Sub
  472. End Class
  473.  
  474. Public Class ThirteenComboBox : Inherits ComboBox
  475. #Region " Control Help - Properties & Flicker Control "
  476.     Enum ColorSchemes
  477.         Light
  478.         Dark
  479.     End Enum
  480.     Private _ColorScheme As ColorSchemes
  481.     Public Property ColorScheme() As ColorSchemes
  482.         Get
  483.             Return _ColorScheme
  484.         End Get
  485.         Set(ByVal value As ColorSchemes)
  486.             _ColorScheme = value
  487.             Invalidate()
  488.         End Set
  489.     End Property
  490.  
  491.     Private _AccentColor As Color
  492.     Public Property AccentColor() As Color
  493.         Get
  494.             Return _AccentColor
  495.         End Get
  496.         Set(ByVal value As Color)
  497.             _AccentColor = value
  498.             Invalidate()
  499.         End Set
  500.     End Property
  501.  
  502.     Private _StartIndex As Integer = 0
  503.     Private Property StartIndex As Integer
  504.         Get
  505.             Return _StartIndex
  506.         End Get
  507.         Set(ByVal value As Integer)
  508.             _StartIndex = value
  509.             Try
  510.                 MyBase.SelectedIndex = value
  511.             Catch
  512.             End Try
  513.             Invalidate()
  514.         End Set
  515.     End Property
  516.     Sub ReplaceItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
  517.         e.DrawBackground()
  518.         Try
  519.             If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
  520.                 e.Graphics.FillRectangle(New SolidBrush(_AccentColor), e.Bounds)
  521.             Else
  522.                 Select Case ColorScheme
  523.                     Case ColorSchemes.Dark
  524.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(35, 35, 35)), e.Bounds)
  525.                     Case ColorSchemes.Light
  526.                         e.Graphics.FillRectangle(New SolidBrush(Color.White), e.Bounds)
  527.                 End Select
  528.             End If
  529.             Select Case ColorScheme
  530.                 Case ColorSchemes.Dark
  531.                     e.Graphics.DrawString(MyBase.GetItemText(MyBase.Items(e.Index)), e.Font, Brushes.White, e.Bounds)
  532.                 Case ColorSchemes.Light
  533.                     e.Graphics.DrawString(MyBase.GetItemText(MyBase.Items(e.Index)), e.Font, Brushes.Black, e.Bounds)
  534.             End Select
  535.         Catch
  536.         End Try
  537.     End Sub
  538.     Protected Sub DrawTriangle(ByVal Clr As Color, ByVal FirstPoint As Point, ByVal SecondPoint As Point, ByVal ThirdPoint As Point, ByVal G As Graphics)
  539.         Dim points As New List(Of Point)()
  540.         points.Add(FirstPoint)
  541.         points.Add(SecondPoint)
  542.         points.Add(ThirdPoint)
  543.         G.FillPolygon(New SolidBrush(Clr), points.ToArray())
  544.     End Sub
  545.  
  546. #End Region
  547.  
  548.     Sub New()
  549.         MyBase.New()
  550.         SetStyle(ControlStyles.AllPaintingInWmPaint, True)
  551.         SetStyle(ControlStyles.ResizeRedraw, True)
  552.         SetStyle(ControlStyles.UserPaint, True)
  553.         SetStyle(ControlStyles.DoubleBuffer, True)
  554.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  555.         DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
  556.         BackColor = Color.FromArgb(50, 50, 50)
  557.         ForeColor = Color.White
  558.         AccentColor = Color.DodgerBlue
  559.         ColorScheme = ColorSchemes.Dark
  560.         DropDownStyle = ComboBoxStyle.DropDownList
  561.         Font = New Font("Segoe UI Semilight", 9.75F)
  562.         StartIndex = 0
  563.         DoubleBuffered = True
  564.     End Sub
  565.  
  566.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  567.         Dim B As New Bitmap(Width, Height)
  568.         Dim G As Graphics = Graphics.FromImage(B)
  569.         Dim Curve As Integer = 2
  570.  
  571.         G.SmoothingMode = SmoothingMode.HighQuality
  572.  
  573.         Select Case ColorScheme
  574.             Case ColorSchemes.Dark
  575.                 G.Clear(Color.FromArgb(50, 50, 50))
  576.                 G.DrawLine(New Pen(Color.White, 2), New Point(Width - 18, 10), New Point(Width - 14, 14))
  577.                 G.DrawLine(New Pen(Color.White, 2), New Point(Width - 14, 14), New Point(Width - 10, 10))
  578.                 G.DrawLine(New Pen(Color.White), New Point(Width - 14, 15), New Point(Width - 14, 14))
  579.             Case ColorSchemes.Light
  580.                 G.Clear(Color.White)
  581.                 G.DrawLine(New Pen(Color.FromArgb(100, 100, 100), 2), New Point(Width - 18, 10), New Point(Width - 14, 14))
  582.                 G.DrawLine(New Pen(Color.FromArgb(100, 100, 100), 2), New Point(Width - 14, 14), New Point(Width - 10, 10))
  583.                 G.DrawLine(New Pen(Color.FromArgb(100, 100, 100)), New Point(Width - 14, 15), New Point(Width - 14, 14))
  584.         End Select
  585.         G.DrawRectangle(New Pen(Color.FromArgb(100, 100, 100)), New Rectangle(0, 0, Width - 1, Height - 1))
  586.  
  587.  
  588.         Try
  589.             Select Case ColorScheme
  590.                 Case ColorSchemes.Dark
  591.                     G.DrawString(Text, Font, Brushes.White, New Rectangle(7, 0, Width - 1, Height - 1), New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})
  592.                 Case ColorSchemes.Light
  593.                     G.DrawString(Text, Font, Brushes.Black, New Rectangle(7, 0, Width - 1, Height - 1), New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})
  594.             End Select
  595.         Catch
  596.         End Try
  597.  
  598.         e.Graphics.DrawImage(B.Clone(), 0, 0)
  599.         G.Dispose() : B.Dispose()
  600.     End Sub
  601. End Class
  602.  
  603. <DefaultEvent("CheckedChanged")> Public Class ThirteenRadioButton : Inherits Control
  604.  
  605. #Region " Control Help - MouseState & Flicker Control"
  606.     Enum MouseState
  607.         None
  608.         Over
  609.         Down
  610.     End Enum
  611.     Enum ColorSchemes
  612.         Dark
  613.         Light
  614.     End Enum
  615.  
  616.     Private State As MouseState = MouseState.None
  617.     Private _ColorScheme As ColorSchemes
  618.     Public Property ColorScheme() As ColorSchemes
  619.         Get
  620.             Return _ColorScheme
  621.         End Get
  622.         Set(ByVal value As ColorSchemes)
  623.             _ColorScheme = value
  624.             Invalidate()
  625.         End Set
  626.     End Property
  627.  
  628.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  629.         MyBase.OnMouseEnter(e)
  630.         State = MouseState.Over
  631.         Invalidate()
  632.     End Sub
  633.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  634.         MyBase.OnMouseDown(e)
  635.         State = MouseState.Down
  636.         Invalidate()
  637.     End Sub
  638.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  639.         MyBase.OnMouseLeave(e)
  640.         State = MouseState.None
  641.         Invalidate()
  642.     End Sub
  643.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  644.         MyBase.OnMouseUp(e)
  645.         State = MouseState.Over
  646.         Invalidate()
  647.     End Sub
  648.     Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
  649.         MyBase.OnResize(e)
  650.         Height = 18
  651.     End Sub
  652.     Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  653.         MyBase.OnTextChanged(e)
  654.         Width = CreateGraphics().MeasureString(Text, Font).Width + (2 * 3.5) + (Height * 2)
  655.         Invalidate()
  656.     End Sub
  657.     Private _Checked As Boolean
  658.     Property Checked() As Boolean
  659.         Get
  660.             Return _Checked
  661.         End Get
  662.         Set(ByVal value As Boolean)
  663.             _Checked = value
  664.             InvalidateControls()
  665.             RaiseEvent CheckedChanged(Me)
  666.             Invalidate()
  667.         End Set
  668.     End Property
  669.     Protected Overrides Sub OnClick(ByVal e As EventArgs)
  670.         If Not _Checked Then Checked = True
  671.         MyBase.OnClick(e)
  672.     End Sub
  673.     Event CheckedChanged(ByVal sender As Object)
  674.     Protected Overrides Sub OnCreateControl()
  675.         MyBase.OnCreateControl()
  676.         InvalidateControls()
  677.     End Sub
  678.     Private Sub InvalidateControls()
  679.         If Not IsHandleCreated OrElse Not _Checked Then Return
  680.  
  681.         For Each C As Control In Parent.Controls
  682.             If C IsNot Me AndAlso TypeOf C Is ThirteenRadioButton Then
  683.                 DirectCast(C, ThirteenRadioButton).Checked = False
  684.             End If
  685.         Next
  686.     End Sub
  687. #End Region
  688.  
  689.     Sub New()
  690.         MyBase.New()
  691.         SetStyle(ControlStyles.UserPaint Or ControlStyles.SupportsTransparentBackColor, True)
  692.         ColorScheme = ColorSchemes.Dark
  693.         BackColor = Color.FromArgb(50, 50, 50)
  694.         ForeColor = Color.White
  695.         DoubleBuffered = True
  696.         Size = New Size(177, 18)
  697.     End Sub
  698.  
  699.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  700.         Dim B As New Bitmap(Width, Height)
  701.         Dim G As Graphics = Graphics.FromImage(B)
  702.         Dim RadioBtnRectangle = New Rectangle(0, 0, Height - 1, Height - 1)
  703.  
  704.         G.SmoothingMode = SmoothingMode.HighQuality
  705.         G.Clear(BackColor)
  706.  
  707.         Select Case ColorScheme
  708.             Case ColorSchemes.Light
  709.                 G.FillEllipse(New SolidBrush(Color.FromArgb(215, Color.Black)), RadioBtnRectangle)
  710.             Case ColorSchemes.Dark
  711.                 G.FillEllipse(New SolidBrush(Color.FromArgb(215, Color.White)), RadioBtnRectangle)
  712.         End Select
  713.  
  714.         If Checked Then
  715.             Select Case ColorScheme
  716.                 Case ColorSchemes.Dark
  717.                     G.FillEllipse(New SolidBrush(Color.Black), New Rectangle(4, 4, Height - 9, Height - 9))
  718.                 Case ColorSchemes.Light
  719.                     G.FillEllipse(New SolidBrush(Color.White), New Rectangle(4, 4, Height - 9, Height - 9))
  720.             End Select
  721.         End If
  722.  
  723.         G.DrawString(Text, Font, New SolidBrush(ForeColor), New Point(22, 1), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  724.  
  725.         e.Graphics.DrawImage(B.Clone(), 0, 0)
  726.         G.Dispose() : B.Dispose()
  727.     End Sub
  728.  
  729. End Class
  730. <DefaultEvent("CheckedChanged")> Public Class ThirteenCheckBox : Inherits Control
  731.  
  732. #Region " Control Help - MouseState & Flicker Control"
  733.     Enum ColorSchemes
  734.         Light
  735.         Dark
  736.     End Enum
  737.     Enum MouseState
  738.         None
  739.         Over
  740.         Down
  741.     End Enum
  742.     Private _ColorScheme As ColorSchemes
  743.     Public Property ColorScheme() As ColorSchemes
  744.         Get
  745.             Return _ColorScheme
  746.         End Get
  747.         Set(ByVal value As ColorSchemes)
  748.             _ColorScheme = value
  749.             Invalidate()
  750.         End Set
  751.     End Property
  752.  
  753.     Private State As MouseState = MouseState.None
  754.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  755.         MyBase.OnMouseEnter(e)
  756.         State = MouseState.Over
  757.         Invalidate()
  758.     End Sub
  759.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  760.         MyBase.OnMouseDown(e)
  761.         State = MouseState.Down
  762.         Invalidate()
  763.     End Sub
  764.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  765.         MyBase.OnMouseLeave(e)
  766.         State = MouseState.None
  767.         Invalidate()
  768.     End Sub
  769.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  770.         MyBase.OnMouseUp(e)
  771.         State = MouseState.Over
  772.         Invalidate()
  773.     End Sub
  774.     Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  775.         MyBase.OnTextChanged(e)
  776.         Width = CreateGraphics().MeasureString(Text, Font).Width + (2 * 3) + Height
  777.         Invalidate()
  778.     End Sub
  779.     Private _Checked As Boolean
  780.     Property Checked() As Boolean
  781.         Get
  782.             Return _Checked
  783.         End Get
  784.         Set(ByVal value As Boolean)
  785.             _Checked = value
  786.             Invalidate()
  787.         End Set
  788.     End Property
  789.     Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
  790.         MyBase.OnResize(e)
  791.         Height = 17
  792.     End Sub
  793.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
  794.         _Checked = Not _Checked
  795.         RaiseEvent CheckedChanged(Me)
  796.         MyBase.OnClick(e)
  797.     End Sub
  798.     Event CheckedChanged(ByVal sender As Object)
  799. #End Region
  800.  
  801.     Sub New()
  802.         MyBase.New()
  803.         SetStyle(ControlStyles.UserPaint, True)
  804.         SetStyle(ControlStyles.AllPaintingInWmPaint, True)
  805.         SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
  806.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  807.  
  808.         ColorScheme = ColorSchemes.Dark
  809.         BackColor = Color.FromArgb(50, 50, 50)
  810.         ForeColor = Color.White
  811.         Size = New Size(147, 17)
  812.         DoubleBuffered = True
  813.     End Sub
  814.  
  815.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  816.         Dim B As New Bitmap(Width, Height)
  817.         Dim G As Graphics = Graphics.FromImage(B)
  818.         G.SmoothingMode = SmoothingMode.HighQuality
  819.         Dim CheckBoxRectangle As New Rectangle(0, 0, Height - 1, Height - 1)
  820.  
  821.         G.Clear(BackColor)
  822.  
  823.         Select Case ColorScheme
  824.             Case ColorSchemes.Light
  825.                 G.FillRectangle(New SolidBrush(Color.FromArgb(215, Color.Black)), CheckBoxRectangle)
  826.             Case ColorSchemes.Dark
  827.                 G.FillRectangle(New SolidBrush(Color.FromArgb(215, Color.White)), CheckBoxRectangle)
  828.         End Select
  829.  
  830.         If Checked Then
  831.             Dim chkPoly As Rectangle = New Rectangle(CheckBoxRectangle.X + CheckBoxRectangle.Width / 4, CheckBoxRectangle.Y + CheckBoxRectangle.Height / 4, CheckBoxRectangle.Width \ 2, CheckBoxRectangle.Height \ 2)
  832.             Dim Poly() As Point = {New Point(chkPoly.X, chkPoly.Y + chkPoly.Height \ 2), New Point(chkPoly.X + chkPoly.Width \ 2, chkPoly.Y + chkPoly.Height), New Point(chkPoly.X + chkPoly.Width, chkPoly.Y)}
  833.             Select Case ColorScheme
  834.                 Case ColorSchemes.Dark
  835.                     For i = 0 To Poly.Length - 2 : G.DrawLine(New Pen(Color.Black, 2), Poly(i), Poly(i + 1)) : Next
  836.                 Case ColorSchemes.Light
  837.                     For i = 0 To Poly.Length - 2 : G.DrawLine(New Pen(Color.White, 2), Poly(i), Poly(i + 1)) : Next
  838.             End Select
  839.         End If
  840.  
  841.         G.DrawString(Text, Font, New SolidBrush(ForeColor), New Point(18, 2), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  842.  
  843.         e.Graphics.DrawImage(B.Clone(), 0, 0)
  844.         G.Dispose() : B.Dispose()
  845.  
  846.     End Sub
  847.  
  848. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement