0Hawk0

Bonfire. Theme

Dec 24th, 2013
1,456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 22.55 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. Class BonfireButton
  20.     Inherits Control
  21.  
  22.     Enum Style
  23.         Blue
  24.         Dark
  25.         Light
  26.     End Enum
  27.  
  28.     Private _style As Style
  29.     Public Property ButtonStyle() As Style
  30.         Get
  31.             Return _style
  32.         End Get
  33.         Set(ByVal value As Style)
  34.             _style = value
  35.             Invalidate()
  36.         End Set
  37.     End Property
  38.  
  39.     Private _image As Image
  40.     Public Property Image() As Image
  41.         Get
  42.             Return _image
  43.         End Get
  44.         Set(ByVal value As Image)
  45.             _image = value
  46.             Invalidate()
  47.         End Set
  48.     End Property
  49.  
  50.     Private _rounded As Boolean
  51.     Public Property RoundedCorners() As Boolean
  52.         Get
  53.             Return _rounded
  54.         End Get
  55.         Set(ByVal value As Boolean)
  56.             _rounded = value
  57.             Invalidate()
  58.         End Set
  59.     End Property
  60.  
  61.     Enum State
  62.         None
  63.         Over
  64.         Down
  65.     End Enum
  66.  
  67.     Private MouseState As State
  68.  
  69.     Sub New()
  70.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  71.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  72.         MouseState = State.None
  73.         Size = New Size(65, 26)
  74.         Font = New Font("Verdana", 8)
  75.         Cursor = Cursors.Hand
  76.     End Sub
  77.  
  78.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  79.         MyBase.OnPaint(e)
  80.  
  81.         Dim G As Graphics = e.Graphics
  82.  
  83.         G.Clear(Parent.BackColor)
  84.         G.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
  85.  
  86.         Dim slope As Integer = 3
  87.  
  88.         Dim shadowRect As New Rectangle(0, 0, Width - 1, Height - 1)
  89.         Dim shadowPath As GraphicsPath = RoundRect(shadowRect, slope)
  90.         Dim mainRect As New Rectangle(0, 0, Width - 2, Height - 2)
  91.         Select Case ButtonStyle
  92.             Case Style.Blue
  93.                 If _rounded Then
  94.                     G.FillPath(New SolidBrush(Color.FromArgb(20, 135, 195)), shadowPath)
  95.                     G.FillPath(New SolidBrush(Color.FromArgb(20, 160, 230)), RoundRect(mainRect, slope))
  96.                 Else
  97.                     G.FillRectangle(New SolidBrush(Color.FromArgb(20, 135, 195)), shadowRect)
  98.                     G.FillRectangle(New SolidBrush(Color.FromArgb(20, 160, 230)), mainRect)
  99.                 End If
  100.             Case Style.Dark
  101.                 If _rounded Then
  102.                     G.FillPath(New SolidBrush(Color.FromArgb(45, 45, 45)), shadowPath)
  103.                     G.FillPath(New SolidBrush(Color.FromArgb(75, 75, 75)), RoundRect(mainRect, slope))
  104.                 Else
  105.                     G.FillRectangle(New SolidBrush(Color.FromArgb(45, 45, 45)), shadowRect)
  106.                     G.FillRectangle(New SolidBrush(Color.FromArgb(75, 75, 75)), mainRect)
  107.                 End If
  108.             Case Style.Light
  109.                 If _rounded Then
  110.                     G.FillPath(New SolidBrush(Color.FromArgb(145, 145, 145)), shadowPath)
  111.                     G.FillPath(New SolidBrush(Color.FromArgb(170, 170, 170)), RoundRect(mainRect, slope))
  112.                 Else
  113.                     G.FillRectangle(New SolidBrush(Color.FromArgb(145, 145, 145)), shadowRect)
  114.                     G.FillRectangle(New SolidBrush(Color.FromArgb(170, 170, 170)), mainRect)
  115.                 End If
  116.         End Select
  117.  
  118.         If _image Is Nothing Then
  119.             Dim textX As Integer = ((Me.Width - 1) / 2) - (G.MeasureString(Text, Font).Width / 2)
  120.             Dim textY As Integer = ((Me.Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  121.             G.DrawString(Text, Font, Brushes.White, textX, textY)
  122.         Else
  123.             Dim textSize As Size = New Size(G.MeasureString(Text, Font).Width, G.MeasureString(Text, Font).Height)
  124.             Dim imageWidth As Integer = Me.Height - 19, imageHeight As Integer = Me.Height - 19
  125.             Dim imageX As Integer = ((Me.Width - 1) / 2) - ((imageWidth + 4 + textSize.Width) / 2)
  126.             Dim imageY As Integer = ((Me.Height - 1) / 2) - (imageHeight / 2)
  127.             G.DrawImage(_image, imageX, imageY, imageWidth, imageHeight)
  128.             G.DrawString(Text, Font, Brushes.White, New Point(imageX + imageWidth + 4, ((Me.Height - 1) / 2) - textSize.Height / 2))
  129.         End If
  130.  
  131.         If MouseState = State.Over Then
  132.             G.FillPath(New SolidBrush(Color.FromArgb(25, Color.White)), shadowPath)
  133.         ElseIf MouseState = State.Down Then
  134.             G.FillPath(New SolidBrush(Color.FromArgb(40, Color.White)), shadowPath)
  135.         End If
  136.  
  137.     End Sub
  138.  
  139.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  140.         MyBase.OnMouseEnter(e)
  141.         MouseState = State.Over
  142.         Invalidate()
  143.     End Sub
  144.  
  145.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  146.         MyBase.OnMouseLeave(e)
  147.         MouseState = State.None
  148.         Invalidate()
  149.     End Sub
  150.  
  151.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  152.         MyBase.OnMouseUp(e)
  153.         MouseState = State.Over
  154.         Invalidate()
  155.     End Sub
  156.  
  157.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  158.         MyBase.OnMouseDown(e)
  159.         MouseState = State.Down
  160.         Invalidate()
  161.     End Sub
  162. End Class
  163.  
  164. Class BonfireTabControl
  165.     Inherits TabControl
  166.  
  167.     Sub New()
  168.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or _
  169.                  ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
  170.         ItemSize = New Size(0, 30)
  171.         Font = New Font("Verdana", 8)
  172.     End Sub
  173.  
  174.     Protected Overrides Sub CreateHandle()
  175.         MyBase.CreateHandle()
  176.         Alignment = TabAlignment.Top
  177.     End Sub
  178.  
  179.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  180.  
  181.         Dim G As Graphics = e.Graphics
  182.  
  183.         Dim borderPen As New Pen(Color.FromArgb(225, 225, 225))
  184.  
  185.         G.SmoothingMode = SmoothingMode.HighQuality
  186.         G.Clear(Parent.BackColor)
  187.  
  188.         Dim fillRect As New Rectangle(2, ItemSize.Height + 2, Width - 6, Height - ItemSize.Height - 3)
  189.         G.FillRectangle(Brushes.White, fillRect)
  190.         G.DrawRectangle(borderPen, fillRect)
  191.  
  192.         Dim FontColor As New Color
  193.  
  194.         For i = 0 To TabCount - 1
  195.  
  196.             Dim mainRect As Rectangle = GetTabRect(i)
  197.  
  198.             If i = SelectedIndex Then
  199.  
  200.                 G.FillRectangle(New SolidBrush(Color.White), mainRect)
  201.                 G.DrawRectangle(borderPen, mainRect)
  202.                 G.DrawLine(New Pen(Color.FromArgb(20, 160, 230)), New Point(mainRect.X + 1, mainRect.Y), New Point(mainRect.X + mainRect.Width - 1, mainRect.Y))
  203.                 G.DrawLine(Pens.White, New Point(mainRect.X + 1, mainRect.Y + mainRect.Height), New Point(mainRect.X + mainRect.Width - 1, mainRect.Y + mainRect.Height))
  204.                 FontColor = Color.FromArgb(20, 160, 230)
  205.  
  206.             Else
  207.  
  208.                 G.FillRectangle(New SolidBrush(Color.FromArgb(245, 245, 245)), mainRect)
  209.                 G.DrawRectangle(borderPen, mainRect)
  210.                 FontColor = Color.FromArgb(160, 160, 160)
  211.  
  212.             End If
  213.  
  214.             Dim titleX As Integer = (mainRect.Location.X + mainRect.Width / 2) - (G.MeasureString(TabPages(i).Text, Font).Width / 2)
  215.             Dim titleY As Integer = (mainRect.Location.Y + mainRect.Height / 2) - (G.MeasureString(TabPages(i).Text, Font).Height / 2)
  216.             G.DrawString(TabPages(i).Text, Font, New SolidBrush(FontColor), New Point(titleX, titleY))
  217.  
  218.             Try : TabPages(i).BackColor = Color.White : Catch : End Try
  219.  
  220.         Next
  221.  
  222.     End Sub
  223.  
  224. End Class
  225.  
  226. Class BonfireGroupBox
  227.     Inherits ContainerControl
  228.  
  229.     Sub New()
  230.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  231.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  232.         BackColor = Color.FromArgb(250, 250, 250)
  233.     End Sub
  234.  
  235.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  236.         MyBase.OnPaint(e)
  237.  
  238.         Dim G As Graphics = e.Graphics
  239.  
  240.         G.SmoothingMode = SmoothingMode.HighQuality
  241.         G.Clear(Parent.BackColor)
  242.  
  243.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  244.         G.FillRectangle(New SolidBrush(Color.FromArgb(250, 250, 250)), mainRect)
  245.         G.DrawRectangle(New Pen(Color.FromArgb(225, 225, 225)), mainRect)
  246.  
  247.     End Sub
  248.  
  249. End Class
  250.  
  251. Class BonfireLabelHeader
  252.     Inherits Label
  253.  
  254.     Sub New()
  255.         Font = New Font("Verdana", 10, FontStyle.Bold)
  256.     End Sub
  257.  
  258. End Class
  259.  
  260. Class BonfireLabel
  261.     Inherits Label
  262.  
  263.     Sub New()
  264.         Font = New Font("Verdana", 8)
  265.         ForeColor = Color.FromArgb(135, 135, 135)
  266.     End Sub
  267.  
  268. End Class
  269.  
  270. Class BonfireProgressBar
  271.     Inherits Control
  272.  
  273.     Private _Maximum As Integer = 100
  274.     Public Property Maximum() As Integer
  275.         Get
  276.             Return _Maximum
  277.         End Get
  278.         Set(ByVal v As Integer)
  279.             If v < 1 Then v = 1
  280.             If v < _Value Then _Value = v
  281.             _Maximum = v
  282.             Invalidate()
  283.         End Set
  284.     End Property
  285.  
  286.     Private _Value As Integer
  287.     Public Property Value() As Integer
  288.         Get
  289.             Return _Value
  290.         End Get
  291.         Set(ByVal v As Integer)
  292.             If v > _Maximum Then v = Maximum
  293.             _Value = v
  294.             Invalidate()
  295.         End Set
  296.     End Property
  297.  
  298.     Sub New()
  299.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  300.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  301.         Size = New Size(100, 40)
  302.     End Sub
  303.  
  304.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  305.         MyBase.OnPaint(e)
  306.  
  307.         Dim G As Graphics = e.Graphics
  308.  
  309.         G.SmoothingMode = SmoothingMode.HighQuality
  310.         G.Clear(Parent.BackColor)
  311.  
  312.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  313.         G.FillRectangle(New SolidBrush(Color.FromArgb(240, 240, 240)), mainRect)
  314.         G.DrawLine(New Pen(Color.FromArgb(230, 230, 230)), New Point(mainRect.X, mainRect.Height), New Point(mainRect.Width, mainRect.Height))
  315.  
  316.         Dim barRect As New Rectangle(0, 0, CInt(((Width / _Maximum) * _Value) - 1), Height - 1)
  317.         G.FillRectangle(New SolidBrush(Color.FromArgb(20, 160, 230)), barRect)
  318.         If _Value > 1 Then G.DrawLine(New Pen(Color.FromArgb(20, 140, 200)), New Point(barRect.X, barRect.Height), New Point(barRect.Width, barRect.Height))
  319.  
  320.         Dim textX As Integer = 12
  321.         Dim textY As Integer = ((Me.Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  322.         Dim percent As Single = (_Value / _Maximum) * 100
  323.         Dim txt As String = Text & " " & CStr(percent) & "%"
  324.         G.DrawString(txt, Font, New SolidBrush(Color.FromArgb(120, 120, 120)), New Point(textX + 1, textY + 1))
  325.         G.DrawString(txt, Font, Brushes.White, New Point(textX, textY))
  326.  
  327.     End Sub
  328.  
  329. End Class
  330.  
  331. Class BonfireAlertBox
  332.     Inherits Control
  333.  
  334.     Private exitLocation As Point
  335.     Private overExit As Boolean
  336.  
  337.     Enum Style
  338.         _Error
  339.         _Success
  340.         _Warning
  341.         _Notice
  342.     End Enum
  343.  
  344.     Private _alertStyle As Style
  345.     Public Property AlertStyle() As Style
  346.         Get
  347.             Return _alertStyle
  348.         End Get
  349.         Set(ByVal value As Style)
  350.             _alertStyle = value
  351.             Invalidate()
  352.         End Set
  353.     End Property
  354.  
  355.     Sub New()
  356.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  357.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  358.         Font = New Font("Verdana", 8)
  359.         Size = New Size(200, 40)
  360.     End Sub
  361.  
  362.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  363.         MyBase.OnPaint(e)
  364.  
  365.         Dim G As Graphics = e.Graphics
  366.  
  367.         G.SmoothingMode = SmoothingMode.HighQuality
  368.         G.Clear(Parent.BackColor)
  369.  
  370.         Dim borderColor, innerColor, textColor As Color
  371.         Select Case _alertStyle
  372.             Case Style._Error
  373.                 borderColor = Color.FromArgb(250, 195, 195)
  374.                 innerColor = Color.FromArgb(255, 235, 235)
  375.                 textColor = Color.FromArgb(220, 90, 90)
  376.             Case Style._Notice
  377.                 borderColor = Color.FromArgb(180, 215, 230)
  378.                 innerColor = Color.FromArgb(235, 245, 255)
  379.                 textColor = Color.FromArgb(80, 145, 180)
  380.             Case Style._Success
  381.                 borderColor = Color.FromArgb(180, 220, 130)
  382.                 innerColor = Color.FromArgb(235, 245, 225)
  383.                 textColor = Color.FromArgb(95, 145, 45)
  384.             Case Style._Warning
  385.                 borderColor = Color.FromArgb(220, 215, 140)
  386.                 innerColor = Color.FromArgb(250, 250, 220)
  387.                 textColor = Color.FromArgb(145, 135, 110)
  388.         End Select
  389.  
  390.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  391.         G.FillRectangle(New SolidBrush(innerColor), mainRect)
  392.         G.DrawRectangle(New Pen(borderColor), mainRect)
  393.  
  394.         Dim styleText As String = Nothing
  395.         Select Case _alertStyle
  396.             Case Style._Error
  397.                 styleText = "Error!"
  398.             Case Style._Notice
  399.                 styleText = "Notice!"
  400.             Case Style._Success
  401.                 styleText = "Success!"
  402.             Case Style._Warning
  403.                 styleText = "Warning!"
  404.         End Select
  405.  
  406.         Dim styleFont As New Font(Font.FontFamily, Font.Size, FontStyle.Bold)
  407.         Dim textY As Integer = ((Me.Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  408.         G.DrawString(styleText, styleFont, New SolidBrush(textColor), New Point(10, textY))
  409.         G.DrawString(Text, Font, New SolidBrush(textColor), New Point(10 + G.MeasureString(styleText, styleFont).Width + 4, textY))
  410.  
  411.         Dim exitFont As New Font("Marlett", 6)
  412.         Dim exitY As Integer = ((Me.Height - 1) / 2) - (G.MeasureString("r", exitFont).Height / 2) + 1
  413.         exitLocation = New Point(Width - 26, exitY - 3)
  414.         G.DrawString("r", exitFont, New SolidBrush(textColor), New Point(Width - 23, exitY))
  415.  
  416.     End Sub
  417.  
  418.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  419.         MyBase.OnMouseMove(e)
  420.  
  421.         If e.X >= Width - 26 AndAlso e.X <= Width - 12 AndAlso e.Y > exitLocation.Y AndAlso e.Y < exitLocation.Y + 12 Then
  422.             If Cursor <> Cursors.Hand Then Cursor = Cursors.Hand
  423.             overExit = True
  424.         Else
  425.             If Cursor <> Cursors.Arrow Then Cursor = Cursors.Arrow
  426.             overExit = False
  427.         End If
  428.  
  429.         Invalidate()
  430.  
  431.     End Sub
  432.  
  433.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  434.         MyBase.OnMouseDown(e)
  435.  
  436.         If overExit Then Me.Visible = False
  437.  
  438.     End Sub
  439.  
  440. End Class
  441.  
  442. Class BonfireCombo
  443.     Inherits ComboBox
  444.  
  445.     Sub New()
  446.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  447.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or _
  448.                  ControlStyles.SupportsTransparentBackColor, True)
  449.         Font = New Font("Verdana", 8)
  450.     End Sub
  451.  
  452.     Protected Overrides Sub CreateHandle()
  453.         MyBase.CreateHandle()
  454.  
  455.         DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
  456.         DropDownStyle = ComboBoxStyle.DropDownList
  457.         DoubleBuffered = True
  458.         ItemHeight = 20
  459.  
  460.     End Sub
  461.  
  462.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  463.         MyBase.OnPaint(e)
  464.  
  465.         Dim G As Graphics = e.Graphics
  466.  
  467.         G.SmoothingMode = SmoothingMode.HighQuality
  468.         G.Clear(Parent.BackColor)
  469.  
  470.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  471.         G.FillRectangle(Brushes.White, mainRect)
  472.         G.DrawRectangle(New Pen(Color.FromArgb(225, 225, 225)), mainRect)
  473.  
  474.         Dim triangle As Point() = New Point() {New Point(Width - 14, 16), New Point(Width - 18, 10), New Point(Width - 10, 10)}
  475.         G.FillPolygon(Brushes.DarkGray, triangle)
  476.         G.DrawLine(New Pen(Color.FromArgb(225, 225, 225)), New Point(Width - 27, 0), New Point(Width - 27, Height - 1))
  477.  
  478.         Try
  479.             If Items.Count > 0 Then
  480.                 If Not SelectedIndex = -1 Then
  481.                     Dim textX As Integer = 6
  482.                     Dim textY As Integer = ((Me.Height - 1) / 2) - (G.MeasureString(Items(SelectedIndex), Font).Height / 2) + 1
  483.                     G.DrawString(Items(SelectedIndex), Font, Brushes.Gray, New Point(textX, textY))
  484.                 Else
  485.                     Dim textX As Integer = 6
  486.                     Dim textY As Integer = ((Me.Height - 1) / 2) - (G.MeasureString(Items(0), Font).Height / 2) + 1
  487.                     G.DrawString(Items(0), Font, Brushes.Gray, New Point(textX, textY))
  488.                 End If
  489.             End If
  490.         Catch : End Try
  491.  
  492.     End Sub
  493.  
  494.     Sub replaceItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
  495.         e.DrawBackground()
  496.  
  497.         Dim G As Graphics = e.Graphics
  498.         G.SmoothingMode = SmoothingMode.HighQuality
  499.  
  500.         Dim rect As New Rectangle(e.Bounds.X - 1, e.Bounds.Y - 1, e.Bounds.Width + 1, e.Bounds.Height + 1)
  501.  
  502.         Try
  503.             If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
  504.                 G.FillRectangle(New SolidBrush(Color.FromArgb(20, 160, 230)), rect)
  505.                 G.DrawString(MyBase.GetItemText(MyBase.Items(e.Index)), Font, Brushes.White, New Rectangle(e.Bounds.X + 6, e.Bounds.Y + 3, e.Bounds.Width, e.Bounds.Height))
  506.                 G.DrawRectangle(New Pen(Color.FromArgb(20, 160, 230)), rect)
  507.             Else
  508.                 G.FillRectangle(Brushes.White, rect)
  509.                 G.DrawString(MyBase.GetItemText(MyBase.Items(e.Index)), Font, Brushes.DarkGray, New Rectangle(e.Bounds.X + 6, e.Bounds.Y + 3, e.Bounds.Width, e.Bounds.Height))
  510.                 G.DrawRectangle(New Pen(Color.FromArgb(20, 160, 230)), rect)
  511.             End If
  512.  
  513.         Catch : End Try
  514.  
  515.     End Sub
  516.  
  517.     Protected Overrides Sub OnSelectedItemChanged(ByVal e As System.EventArgs)
  518.         MyBase.OnSelectedItemChanged(e)
  519.         Invalidate()
  520.     End Sub
  521.  
  522. End Class
  523.  
  524. <DefaultEvent("CheckedChanged")> Class BonfireCheckbox
  525.     Inherits Control
  526.  
  527.     Event CheckedChanged(ByVal sender As Object)
  528.  
  529.     Private _checked As Boolean
  530.     Public Property Checked() As Boolean
  531.         Get
  532.             Return _checked
  533.         End Get
  534.         Set(ByVal value As Boolean)
  535.             _checked = value
  536.             Invalidate()
  537.         End Set
  538.     End Property
  539.  
  540.     Sub New()
  541.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  542.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  543.         Size = New Size(140, 20)
  544.         Font = New Font("Verdana", 8)
  545.     End Sub
  546.  
  547.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  548.  
  549.         Dim G As Graphics = e.Graphics
  550.  
  551.         G.SmoothingMode = SmoothingMode.HighQuality
  552.         G.Clear(Parent.BackColor)
  553.  
  554.         Dim box As New Rectangle(0, 0, Height, Height - 1)
  555.         G.FillRectangle(Brushes.White, box)
  556.         G.DrawRectangle(New Pen(Color.FromArgb(225, 225, 225)), box)
  557.  
  558.         Dim markPen As New Pen(Color.FromArgb(150, 155, 160))
  559.         Dim lightMarkPen As New Pen(Color.FromArgb(170, 175, 180))
  560.         If _checked Then G.DrawString("a", New Font("Marlett", 14), Brushes.Gray, New Point(0, 0))
  561.  
  562.         Dim textY As Integer = (Height / 2) - (G.MeasureString(Text, Font).Height / 2)
  563.         G.DrawString(Text, Font, Brushes.Gray, New Point(24, textY))
  564.  
  565.     End Sub
  566.  
  567.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  568.         MyBase.OnMouseDown(e)
  569.  
  570.         If _checked Then
  571.             _checked = False
  572.         Else
  573.             _checked = True
  574.         End If
  575.  
  576.         RaiseEvent CheckedChanged(Me)
  577.         Invalidate()
  578.  
  579.     End Sub
  580.  
  581. End Class
  582.  
  583. <DefaultEvent("CheckedChanged")> Class BonfireRadioButton
  584.     Inherits Control
  585.  
  586.     Event CheckedChanged(ByVal sender As Object)
  587.  
  588.     Private _checked As Boolean
  589.     Public Property Checked() As Boolean
  590.         Get
  591.             Return _checked
  592.         End Get
  593.         Set(ByVal value As Boolean)
  594.             _checked = value
  595.             Invalidate()
  596.         End Set
  597.     End Property
  598.  
  599.     Sub New()
  600.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  601.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  602.         Size = New Size(140, 20)
  603.         Font = New Font("Verdana", 8)
  604.     End Sub
  605.  
  606.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  607.  
  608.         Dim G As Graphics = e.Graphics
  609.  
  610.         G.SmoothingMode = SmoothingMode.HighQuality
  611.         G.Clear(Parent.BackColor)
  612.  
  613.         Dim box As New Rectangle(0, 0, Height - 1, Height - 1)
  614.         G.FillEllipse(Brushes.White, box)
  615.         G.DrawEllipse(New Pen(Color.FromArgb(225, 225, 225)), box)
  616.  
  617.         If _checked Then
  618.             Dim innerMark As New Rectangle(6, 6, Height - 13, Height - 13)
  619.             G.FillEllipse(New SolidBrush(Color.FromArgb(20, 160, 230)), innerMark)
  620.         End If
  621.  
  622.         Dim textY As Integer = (Height / 2) - (G.MeasureString(Text, Font).Height / 2)
  623.         G.DrawString(Text, Font, Brushes.Gray, New Point(24, textY))
  624.  
  625.     End Sub
  626.  
  627.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  628.         MyBase.OnMouseDown(e)
  629.  
  630.         For Each C As Control In Parent.Controls
  631.             If C IsNot Me AndAlso TypeOf C Is BonfireRadioButton Then
  632.                 DirectCast(C, BonfireRadioButton).Checked = False
  633.             End If
  634.         Next
  635.  
  636.         If _checked Then
  637.             _checked = False
  638.         Else
  639.             _checked = True
  640.         End If
  641.  
  642.         RaiseEvent CheckedChanged(Me)
  643.         Invalidate()
  644.  
  645.     End Sub
  646.  
  647. End Class
Advertisement
Add Comment
Please, Sign In to add comment