Advertisement
Guest User

[GDI+] Element Theme [VB.NET]

a guest
Dec 23rd, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 21.36 KB | None | 0 0
  1. Imports System.Drawing
  2. Imports System.Drawing.Drawing2D
  3. Imports System.ComponentModel
  4. Imports System.Drawing.Text
  5.  
  6. ''' <summary>
  7. ''' Element Theme
  8. ''' Created by Earn
  9. ''' From HF
  10. ''' </summary>
  11. ''' <remarks></remarks>
  12.  
  13. Enum MouseState
  14.     None = 0
  15.     Over = 1
  16.     Down = 2
  17. End Enum
  18.  
  19. Class ElementTheme
  20.     Inherits ContainerControl
  21.  
  22. #Region " Declarations "
  23.     Dim _Down As Boolean = False
  24.     Dim _Header As Integer = 30
  25.     Dim _MousePoint As Point
  26. #End Region
  27.  
  28. #Region " MouseStates "
  29.  
  30.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  31.         MyBase.OnMouseUp(e)
  32.         _Down = False
  33.     End Sub
  34.  
  35.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  36.         MyBase.OnMouseDown(e)
  37.         If e.Location.Y < _Header AndAlso e.Button = Windows.Forms.MouseButtons.Left Then
  38.             _Down = True
  39.             _MousePoint = e.Location
  40.         End If
  41.     End Sub
  42.  
  43.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  44.         MyBase.OnMouseMove(e)
  45.         If _Down = True Then
  46.             ParentForm.Location = MousePosition - _MousePoint
  47.         End If
  48.     End Sub
  49.  
  50. #End Region
  51.  
  52. #Region " Properties "
  53.  
  54.     Private _CenterText As Boolean
  55.     Public Property CenterText() As Boolean
  56.         Get
  57.             Return CenterText
  58.         End Get
  59.         Set(ByVal value As Boolean)
  60.             _CenterText = value
  61.         End Set
  62.     End Property
  63.  
  64.  
  65. #End Region
  66.  
  67.     Protected Overrides Sub OnCreateControl()
  68.         MyBase.OnCreateControl()
  69.         ParentForm.FormBorderStyle = FormBorderStyle.None
  70.         ParentForm.TransparencyKey = Color.Fuchsia
  71.         Dock = DockStyle.Fill
  72.         Invalidate()
  73.     End Sub
  74.  
  75.     Sub New()
  76.         BackColor = Color.FromArgb(41, 41, 41)
  77.     End Sub
  78.  
  79.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  80.         MyBase.OnPaint(e)
  81.         Dim G = e.Graphics
  82.         G.Clear(Color.FromArgb(32, 32, 32))
  83.         G.FillRectangle(New SolidBrush(BackColor), New Rectangle(9, _Header, Width - 18, Height - _Header - 9))
  84.         If _CenterText = True Then
  85.             Dim _StringF As New StringFormat
  86.             _StringF.Alignment = StringAlignment.Center
  87.             _StringF.LineAlignment = StringAlignment.Center
  88.             G.DrawString(Text, New Font("Arial", 11), Brushes.White, New RectangleF(0, 0, Width, _Header), _StringF)
  89.         Else
  90.             G.DrawString(Text, New Font("Arial", 11), Brushes.White, New Point(8, 7))
  91.         End If
  92.     End Sub
  93. End Class
  94.  
  95. Class ElementButton
  96.     Inherits Control
  97.  
  98. #Region " Declarations "
  99.     Private _State As MouseState
  100. #End Region
  101.  
  102. #Region " MouseStates "
  103.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  104.         MyBase.OnMouseEnter(e)
  105.         _State = MouseState.Over
  106.         Invalidate()
  107.     End Sub
  108.  
  109.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  110.         MyBase.OnMouseLeave(e)
  111.         _State = MouseState.None
  112.         Invalidate()
  113.     End Sub
  114.  
  115.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  116.         MyBase.OnMouseDown(e)
  117.         _State = MouseState.Down
  118.         Invalidate()
  119.     End Sub
  120.  
  121.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  122.         MyBase.OnMouseUp(e)
  123.         _State = MouseState.Over
  124.         Invalidate()
  125.     End Sub
  126. #End Region
  127.  
  128.     Sub New()
  129.         Size = New Size(90, 30)
  130.     End Sub
  131.  
  132.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  133.         MyBase.OnPaint(e)
  134.         Dim G = e.Graphics
  135.         G.Clear(Color.FromArgb(231, 75, 60))
  136.  
  137.         Select Case _State
  138.             Case MouseState.Over
  139.                 G.FillRectangle(New SolidBrush(Color.FromArgb(20, Color.White)), New Rectangle(0, 0, Width, Height))
  140.  
  141.             Case MouseState.Down
  142.                 G.FillRectangle(New SolidBrush(Color.FromArgb(30, Color.Black)), New Rectangle(0, 0, Width, Height))
  143.         End Select
  144.  
  145.         Dim _StringF As New StringFormat
  146.         _StringF.Alignment = StringAlignment.Center
  147.         _StringF.LineAlignment = StringAlignment.Center
  148.         G.DrawString(Text, New Font("Arial", 9), Brushes.White, New RectangleF(0, 0, Width, Height), _StringF)
  149.  
  150.     End Sub
  151.  
  152. End Class
  153.  
  154. Class ElementGroupBox
  155.     Inherits ContainerControl
  156.  
  157.     Sub New()
  158.         Size = New Size(200, 100)
  159.         BackColor = Color.FromArgb(32, 32, 32)
  160.     End Sub
  161.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  162.         MyBase.OnPaint(e)
  163.         Dim G = e.Graphics
  164.         G.Clear(Color.FromArgb(32, 32, 32))
  165.  
  166.         G.FillRectangle(New SolidBrush(Color.FromArgb(231, 75, 60)), New Rectangle(0, 0, 7, Height))
  167.         G.DrawString(Text, New Font("Arial", 9), Brushes.White, New Point(10, 4))
  168.     End Sub
  169. End Class
  170.  
  171. Class ElementRadioButton
  172.     Inherits Control
  173.  
  174. #Region " Variables "
  175.  
  176.     Private _State As MouseState
  177.     Private _Checked As Boolean
  178.  
  179. #End Region
  180.  
  181. #Region " Properties "
  182.     Property Checked() As Boolean
  183.         Get
  184.             Return _Checked
  185.         End Get
  186.         Set(value As Boolean)
  187.             _Checked = value
  188.             InvalidateControls()
  189.             RaiseEvent CheckedChanged(Me)
  190.             Invalidate()
  191.         End Set
  192.     End Property
  193.  
  194.     Event CheckedChanged(ByVal sender As Object)
  195.     Protected Overrides Sub OnClick(e As EventArgs)
  196.         If Not _Checked Then Checked = True
  197.         MyBase.OnClick(e)
  198.     End Sub
  199.     Private Sub InvalidateControls()
  200.         If Not IsHandleCreated OrElse Not _Checked Then Return
  201.         For Each C As Control In Parent.Controls
  202.             If C IsNot Me AndAlso TypeOf C Is ElementRadioButton Then
  203.                 DirectCast(C, ElementRadioButton).Checked = False
  204.                 Invalidate()
  205.             End If
  206.         Next
  207.     End Sub
  208.     Protected Overrides Sub OnCreateControl()
  209.         MyBase.OnCreateControl()
  210.         InvalidateControls()
  211.     End Sub
  212.  
  213.  
  214.     Protected Overrides Sub OnResize(e As EventArgs)
  215.         MyBase.OnResize(e)
  216.         Height = 16
  217.     End Sub
  218.  
  219. #Region " Mouse States "
  220.  
  221.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  222.         MyBase.OnMouseDown(e)
  223.         _State = MouseState.Down : Invalidate()
  224.     End Sub
  225.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  226.         MyBase.OnMouseUp(e)
  227.         _State = MouseState.Over : Invalidate()
  228.     End Sub
  229.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  230.         MyBase.OnMouseEnter(e)
  231.         _State = MouseState.Over : Invalidate()
  232.     End Sub
  233.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  234.         MyBase.OnMouseLeave(e)
  235.         _State = MouseState.None : Invalidate()
  236.     End Sub
  237.  
  238. #End Region
  239.  
  240. #End Region
  241.  
  242.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  243.         MyBase.OnPaint(e)
  244.         Dim G = e.Graphics
  245.         G.SmoothingMode = 2
  246.         G.TextRenderingHint = 5
  247.         G.Clear(Parent.BackColor)
  248.         G.FillEllipse(Brushes.White, New Rectangle(0, 0, 15, 15))
  249.         If Checked Then
  250.             G.FillEllipse(New SolidBrush(Color.FromArgb(231, 75, 60)), New Rectangle(2, 2, 11, 11))
  251.         End If
  252.         G.DrawString(Text, New Font("Arial", 9), Brushes.White, New Point(20, 0))
  253.     End Sub
  254. End Class
  255.  
  256. Class ElementCheckBox
  257.     Inherits Control
  258.  
  259. #Region " Variables "
  260.  
  261.     Private _State As MouseState
  262.     Private _Checked As Boolean
  263.  
  264. #End Region
  265.  
  266. #Region " Properties "
  267.     Property Checked() As Boolean
  268.         Get
  269.             Return _Checked
  270.         End Get
  271.         Set(value As Boolean)
  272.             _Checked = value
  273.             RaiseEvent CheckedChanged(Me)
  274.             Invalidate()
  275.         End Set
  276.     End Property
  277.  
  278.     Event CheckedChanged(ByVal sender As Object)
  279.     Protected Overrides Sub OnClick(e As EventArgs)
  280.         If Not _Checked Then Checked = True
  281.         MyBase.OnClick(e)
  282.     End Sub
  283.  
  284.  
  285.     Protected Overrides Sub OnResize(e As EventArgs)
  286.         MyBase.OnResize(e)
  287.         Height = 16
  288.     End Sub
  289.  
  290. #Region " Mouse States "
  291.  
  292.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  293.         MyBase.OnMouseDown(e)
  294.         _State = MouseState.Down : Invalidate()
  295.     End Sub
  296.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  297.         MyBase.OnMouseUp(e)
  298.         _State = MouseState.Over : Invalidate()
  299.     End Sub
  300.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  301.         MyBase.OnMouseEnter(e)
  302.         _State = MouseState.Over : Invalidate()
  303.     End Sub
  304.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  305.         MyBase.OnMouseLeave(e)
  306.         _State = MouseState.None : Invalidate()
  307.     End Sub
  308.  
  309. #End Region
  310.  
  311. #End Region
  312.  
  313.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  314.         MyBase.OnPaint(e)
  315.         Dim G = e.Graphics
  316.         G.TextRenderingHint = 5
  317.         G.Clear(Parent.BackColor)
  318.         G.FillRectangle(Brushes.White, New Rectangle(0, 0, 15, 15))
  319.         If Checked = True Then
  320.             G.FillRectangle(New SolidBrush(Color.FromArgb(231, 75, 60)), New Rectangle(2, 2, 11, 11))
  321.         End If
  322.         G.DrawString(Text, New Font("Arial", 9), Brushes.White, New Point(20, 0))
  323.     End Sub
  324. End Class
  325.  
  326. Class ElementProgressBar
  327.     Inherits Control
  328.  
  329. #Region " Variables"
  330.  
  331.     Private _Value As Integer = 0
  332.     Private _Maximum As Integer = 100
  333.  
  334. #End Region
  335.  
  336. #Region " Control"
  337.     <Category("Control")>
  338.     Public Property Maximum() As Integer
  339.         Get
  340.             Return _Maximum
  341.         End Get
  342.         Set(V As Integer)
  343.             Select Case V
  344.                 Case Is < _Value
  345.                     _Value = V
  346.             End Select
  347.             _Maximum = V
  348.             Invalidate()
  349.         End Set
  350.     End Property
  351.  
  352.     <Category("Control")>
  353.     Public Property Value() As Integer
  354.         Get
  355.             Select Case _Value
  356.                 Case 0
  357.                     Return 0
  358.                     Invalidate()
  359.                 Case Else
  360.                     Return _Value
  361.                     Invalidate()
  362.             End Select
  363.         End Get
  364.         Set(V As Integer)
  365.             Select Case V
  366.                 Case Is > _Maximum
  367.                     V = _Maximum
  368.                     Invalidate()
  369.             End Select
  370.             _Value = V
  371.             Invalidate()
  372.         End Set
  373.     End Property
  374. #End Region
  375.  
  376. #Region "Events"
  377.     Protected Overrides Sub OnResize(e As EventArgs)
  378.         MyBase.OnResize(e)
  379.         Height = 25
  380.     End Sub
  381.  
  382.     Protected Overrides Sub CreateHandle()
  383.         MyBase.CreateHandle()
  384.         Height = 25
  385.     End Sub
  386.  
  387.     Public Sub Increment(ByVal Amount As Integer)
  388.         Value += Amount
  389.     End Sub
  390. #End Region
  391.  
  392.     Sub New()
  393.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
  394.                  ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
  395.         DoubleBuffered = True
  396.     End Sub
  397.  
  398.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  399.         MyBase.OnPaint(e)
  400.         Dim G = e.Graphics
  401.  
  402.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  403.         G.SmoothingMode = SmoothingMode.HighQuality
  404.         G.PixelOffsetMode = PixelOffsetMode.HighQuality
  405.  
  406.         G.Clear(Parent.BackColor)
  407.         Dim ProgVal As Integer = CInt(_Value / _Maximum * Width)
  408.         G.FillRectangle(New SolidBrush(Color.White), New Rectangle(0, 0, Width, Height))
  409.         G.FillRectangle(New SolidBrush(Color.FromArgb(236, 75, 60)), New Rectangle(0, 0, ProgVal, Height))
  410.         G.InterpolationMode = CType(7, InterpolationMode)
  411.     End Sub
  412. End Class
  413.  
  414. <DefaultEvent("TextChanged")>
  415. Class ElementTextBox
  416.     Inherits Control
  417.  
  418. #Region " Variables"
  419.     Private WithEvents _TextBox As Windows.Forms.TextBox
  420. #End Region
  421.  
  422. #Region " Properties"
  423.  
  424. #Region " TextBox Properties"
  425.  
  426.     Private _TextAlign As HorizontalAlignment = HorizontalAlignment.Left
  427.     <Category("Options")> _
  428.     Property TextAlign() As HorizontalAlignment
  429.         Get
  430.             Return _TextAlign
  431.         End Get
  432.         Set(ByVal value As HorizontalAlignment)
  433.             _TextAlign = value
  434.             If _TextBox IsNot Nothing Then
  435.                 _TextBox.TextAlign = value
  436.             End If
  437.         End Set
  438.     End Property
  439.     Private _MaxLength As Integer = 32767
  440.     <Category("Options")> _
  441.     Property MaxLength() As Integer
  442.         Get
  443.             Return _MaxLength
  444.         End Get
  445.         Set(ByVal value As Integer)
  446.             _MaxLength = value
  447.             If _TextBox IsNot Nothing Then
  448.                 _TextBox.MaxLength = value
  449.             End If
  450.         End Set
  451.     End Property
  452.     Private _ReadOnly As Boolean
  453.     <Category("Options")> _
  454.     Property [ReadOnly]() As Boolean
  455.         Get
  456.             Return _ReadOnly
  457.         End Get
  458.         Set(ByVal value As Boolean)
  459.             _ReadOnly = value
  460.             If _TextBox IsNot Nothing Then
  461.                 _TextBox.ReadOnly = value
  462.             End If
  463.         End Set
  464.     End Property
  465.     Private _UseSystemPasswordChar As Boolean
  466.     <Category("Options")> _
  467.     Property UseSystemPasswordChar() As Boolean
  468.         Get
  469.             Return _UseSystemPasswordChar
  470.         End Get
  471.         Set(ByVal value As Boolean)
  472.             _UseSystemPasswordChar = value
  473.             If _TextBox IsNot Nothing Then
  474.                 _TextBox.UseSystemPasswordChar = value
  475.             End If
  476.         End Set
  477.     End Property
  478.     Private _Multiline As Boolean
  479.     <Category("Options")> _
  480.     Property Multiline() As Boolean
  481.         Get
  482.             Return _Multiline
  483.         End Get
  484.         Set(ByVal value As Boolean)
  485.             _Multiline = value
  486.             If _TextBox IsNot Nothing Then
  487.                 _TextBox.Multiline = value
  488.  
  489.                 If value Then
  490.                     _TextBox.Height = Height - 11
  491.                 Else
  492.                     Height = _TextBox.Height + 11
  493.                 End If
  494.  
  495.             End If
  496.         End Set
  497.     End Property
  498.     <Category("Options")> _
  499.     Overrides Property Text As String
  500.         Get
  501.             Return MyBase.Text
  502.         End Get
  503.         Set(ByVal value As String)
  504.             MyBase.Text = value
  505.             If _TextBox IsNot Nothing Then
  506.                 _TextBox.Text = value
  507.             End If
  508.         End Set
  509.     End Property
  510.     <Category("Options")> _
  511.     Overrides Property Font As Font
  512.         Get
  513.             Return MyBase.Font
  514.         End Get
  515.         Set(ByVal value As Font)
  516.             MyBase.Font = value
  517.             If _TextBox IsNot Nothing Then
  518.                 _TextBox.Font = value
  519.                 _TextBox.Location = New Point(3, 5)
  520.                 _TextBox.Width = Width - 6
  521.  
  522.                 If Not _Multiline Then
  523.                     Height = _TextBox.Height + 11
  524.                 End If
  525.             End If
  526.         End Set
  527.     End Property
  528.  
  529.     Protected Overrides Sub OnCreateControl()
  530.         MyBase.OnCreateControl()
  531.         If Not Controls.Contains(_TextBox) Then
  532.             Controls.Add(_TextBox)
  533.         End If
  534.     End Sub
  535.     Private Sub OnBaseTextChanged(ByVal s As Object, ByVal e As EventArgs)
  536.         Text = _TextBox.Text
  537.     End Sub
  538.     Private Sub OnBaseKeyDown(ByVal s As Object, ByVal e As KeyEventArgs)
  539.         If e.Control AndAlso e.KeyCode = Keys.A Then
  540.             _TextBox.SelectAll()
  541.             e.SuppressKeyPress = True
  542.         End If
  543.         If e.Control AndAlso e.KeyCode = Keys.C Then
  544.             _TextBox.Copy()
  545.             e.SuppressKeyPress = True
  546.         End If
  547.     End Sub
  548.     Protected Overrides Sub OnResize(ByVal e As EventArgs)
  549.         _TextBox.Location = New Point(5, 5)
  550.         _TextBox.Width = Width - 10
  551.  
  552.         If _Multiline Then
  553.             _TextBox.Height = Height - 11
  554.         Else
  555.             Height = _TextBox.Height + 11
  556.         End If
  557.         MyBase.OnResize(e)
  558.     End Sub
  559.  
  560. #End Region
  561. #End Region
  562.     Sub New()
  563.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
  564.                  ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or _
  565.                  ControlStyles.SupportsTransparentBackColor, True)
  566.         DoubleBuffered = True
  567.  
  568.         BackColor = Color.Transparent
  569.  
  570.         _TextBox = New Windows.Forms.TextBox
  571.         _TextBox.Font = New Font("Segoe UI", 10)
  572.         _TextBox.Text = Text
  573.         _TextBox.BackColor = Color.FromArgb(32, 32, 32)
  574.         _TextBox.ForeColor = Color.White
  575.         _TextBox.MaxLength = _MaxLength
  576.         _TextBox.Multiline = _Multiline
  577.         _TextBox.ReadOnly = _ReadOnly
  578.         _TextBox.UseSystemPasswordChar = _UseSystemPasswordChar
  579.         _TextBox.BorderStyle = BorderStyle.None
  580.         _TextBox.Location = New Point(5, 5)
  581.         _TextBox.Width = Width - 10
  582.  
  583.         _TextBox.Cursor = Cursors.IBeam
  584.  
  585.         If _Multiline Then
  586.             _TextBox.Height = Height - 11
  587.         Else
  588.             Height = _TextBox.Height + 11
  589.         End If
  590.  
  591.         AddHandler _TextBox.TextChanged, AddressOf OnBaseTextChanged
  592.         AddHandler _TextBox.KeyDown, AddressOf OnBaseKeyDown
  593.     End Sub
  594.  
  595.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  596.         MyBase.OnPaint(e)
  597.         Dim G = e.Graphics
  598.         G.Clear(Color.FromArgb(32, 32, 32))
  599.         G.DrawRectangle(New Pen(Color.FromArgb(236, 75, 60)), New Rectangle(0, 0, Width - 1, Height - 1))
  600.     End Sub
  601. End Class
  602.  
  603. Class ElementClose
  604.     Inherits Control
  605.  
  606. #Region " Declarations "
  607.     Private _State As MouseState
  608. #End Region
  609.  
  610. #Region " MouseStates "
  611.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  612.         MyBase.OnMouseEnter(e)
  613.         _State = MouseState.Over
  614.         Invalidate()
  615.     End Sub
  616.  
  617.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  618.         MyBase.OnMouseLeave(e)
  619.         _State = MouseState.None
  620.         Invalidate()
  621.     End Sub
  622.  
  623.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  624.         MyBase.OnMouseDown(e)
  625.         _State = MouseState.Down
  626.         Invalidate()
  627.     End Sub
  628.  
  629.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  630.         MyBase.OnMouseUp(e)
  631.         _State = MouseState.Over
  632.         Invalidate()
  633.     End Sub
  634.  
  635.     Protected Overrides Sub OnClick(e As EventArgs)
  636.         MyBase.OnClick(e)
  637.         Environment.Exit(0)
  638.     End Sub
  639. #End Region
  640.  
  641.     Protected Overrides Sub OnResize(e As EventArgs)
  642.         MyBase.OnResize(e)
  643.         Size = New Size(12, 12)
  644.     End Sub
  645.  
  646.     Sub New()
  647.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
  648.                 ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
  649.         DoubleBuffered = True
  650.         Size = New Size(12, 12)
  651.     End Sub
  652.  
  653.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  654.         MyBase.OnPaint(e)
  655.         Dim G = e.Graphics
  656.  
  657.         G.Clear(Color.FromArgb(32, 32, 32))
  658.  
  659.         Dim _StringF As New StringFormat
  660.         _StringF.Alignment = StringAlignment.Center
  661.         _StringF.LineAlignment = StringAlignment.Center
  662.  
  663.         G.DrawString("r", New Font("Marlett", 11), Brushes.White, New RectangleF(0, 0, Width, Height), _StringF)
  664.  
  665.         Select Case _State
  666.             Case MouseState.Over
  667.                 G.DrawString("r", New Font("Marlett", 11), New SolidBrush(Color.FromArgb(25, Color.White)), New RectangleF(0, 0, Width, Height), _StringF)
  668.  
  669.             Case MouseState.Down
  670.                 G.DrawString("r", New Font("Marlett", 11), New SolidBrush(Color.FromArgb(40, Color.Black)), New RectangleF(0, 0, Width, Height), _StringF)
  671.  
  672.         End Select
  673.  
  674.     End Sub
  675.  
  676. End Class
  677.  
  678. Class ElementMini
  679.     Inherits Control
  680.  
  681. #Region " Declarations "
  682.     Private _State As MouseState
  683. #End Region
  684.  
  685. #Region " MouseStates "
  686.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  687.         MyBase.OnMouseEnter(e)
  688.         _State = MouseState.Over
  689.         Invalidate()
  690.     End Sub
  691.  
  692.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  693.         MyBase.OnMouseLeave(e)
  694.         _State = MouseState.None
  695.         Invalidate()
  696.     End Sub
  697.  
  698.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  699.         MyBase.OnMouseDown(e)
  700.         _State = MouseState.Down
  701.         Invalidate()
  702.     End Sub
  703.  
  704.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  705.         MyBase.OnMouseUp(e)
  706.         _State = MouseState.Over
  707.         Invalidate()
  708.     End Sub
  709.  
  710.     Protected Overrides Sub OnClick(e As EventArgs)
  711.         MyBase.OnClick(e)
  712.         FindForm.WindowState = FormWindowState.Minimized
  713.     End Sub
  714. #End Region
  715.  
  716.     Protected Overrides Sub OnResize(e As EventArgs)
  717.         MyBase.OnResize(e)
  718.         Size = New Size(12, 12)
  719.     End Sub
  720.  
  721.     Sub New()
  722.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
  723.                 ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
  724.         DoubleBuffered = True
  725.         Size = New Size(12, 12)
  726.     End Sub
  727.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  728.         MyBase.OnPaint(e)
  729.         Dim G = e.Graphics
  730.  
  731.         G.Clear(Color.FromArgb(32, 32, 32))
  732.  
  733.         Dim _StringF As New StringFormat
  734.         _StringF.Alignment = StringAlignment.Center
  735.         _StringF.LineAlignment = StringAlignment.Center
  736.  
  737.         G.DrawString("0", New Font("Marlett", 11), Brushes.White, New RectangleF(0, 0, Width, Height), _StringF)
  738.  
  739.         Select Case _State
  740.             Case MouseState.Over
  741.                 G.DrawString("0", New Font("Marlett", 11), New SolidBrush(Color.FromArgb(25, Color.White)), New RectangleF(0, 0, Width, Height), _StringF)
  742.  
  743.             Case MouseState.Down
  744.                 G.DrawString("0", New Font("Marlett", 11), New SolidBrush(Color.FromArgb(40, Color.Black)), New RectangleF(0, 0, Width, Height), _StringF)
  745.  
  746.         End Select
  747.  
  748.     End Sub
  749.  
  750. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement