Advertisement
3DotDev

Combobox Xertz LoginTheme BugFix

Jul 10th, 2014
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.52 KB | None | 0 0
  1.     Public Class LogInComboBox
  2.         Inherits ComboBox
  3.  
  4. #Region "Declarations"
  5.         Private _BorderColour As Color = Color.FromArgb(35, 35, 35)
  6.         Private _BaseColour As Color = Color.FromArgb(42, 42, 42)
  7.         Private _FontColour As Color = Color.FromArgb(255, 255, 255)
  8.         Private _LineColour As Color = Color.FromArgb(23, 119, 151)
  9.         Private _SqaureColour As Color = Color.FromArgb(47, 47, 47)
  10.         Private _ArrowColour As Color = Color.FromArgb(30, 30, 30)
  11.         Private _SqaureHoverColour As Color = Color.FromArgb(52, 52, 52)
  12.         Private State As MouseState = MouseState.None
  13. #End Region
  14.  
  15. #Region "Properties & Events"
  16.  
  17.         <Category("Colours")>
  18.         Public Property LineColour As Color
  19.             Get
  20.                 Return _LineColour
  21.             End Get
  22.             Set(value As Color)
  23.                 _LineColour = value
  24.             End Set
  25.         End Property
  26.  
  27.         <Category("Colours")>
  28.         Public Property SqaureColour As Color
  29.             Get
  30.                 Return _SqaureColour
  31.             End Get
  32.             Set(value As Color)
  33.                 _SqaureColour = value
  34.             End Set
  35.         End Property
  36.  
  37.         <Category("Colours")>
  38.         Public Property ArrowColour As Color
  39.             Get
  40.                 Return _ArrowColour
  41.             End Get
  42.             Set(value As Color)
  43.                 _ArrowColour = value
  44.             End Set
  45.         End Property
  46.  
  47.         <Category("Colours")>
  48.         Public Property SqaureHoverColour As Color
  49.             Get
  50.                 Return _SqaureHoverColour
  51.             End Get
  52.             Set(value As Color)
  53.                 _SqaureHoverColour = value
  54.             End Set
  55.         End Property
  56.  
  57.         Protected Overrides Sub OnMouseEnter(e As EventArgs)
  58.             MyBase.OnMouseEnter(e)
  59.             State = MouseState.Over : Invalidate()
  60.         End Sub
  61.  
  62.         Protected Overrides Sub OnMouseLeave(e As EventArgs)
  63.             MyBase.OnMouseLeave(e)
  64.             State = MouseState.None : Invalidate()
  65.         End Sub
  66.  
  67.         <Category("Colours")>
  68.         Public Property BorderColour As Color
  69.             Get
  70.                 Return _BorderColour
  71.             End Get
  72.             Set(value As Color)
  73.                 _BorderColour = value
  74.             End Set
  75.         End Property
  76.  
  77.         <Category("Colours")>
  78.         Public Property BaseColour As Color
  79.             Get
  80.                 Return _BaseColour
  81.             End Get
  82.             Set(value As Color)
  83.                 _BaseColour = value
  84.             End Set
  85.         End Property
  86.  
  87.         <Category("Colours")>
  88.         Public Property FontColour As Color
  89.             Get
  90.                 Return _FontColour
  91.             End Get
  92.             Set(value As Color)
  93.                 _FontColour = value
  94.             End Set
  95.       End Property
  96.  
  97.         Protected Overrides Sub OnSelectedItemChanged(e As System.EventArgs)
  98.             MyBase.OnSelectedItemChanged(e)
  99.         End Sub
  100.  
  101.         Protected Overrides Sub OnTextChanged(e As System.EventArgs)
  102.             MyBase.OnTextChanged(e)
  103.             Invalidate()
  104.         End Sub
  105.  
  106.         Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  107.             Invalidate()
  108.             OnMouseClick(e)
  109.         End Sub
  110.  
  111.         Protected Overrides Sub OnMouseUp(e As System.Windows.Forms.MouseEventArgs)
  112.             Invalidate()
  113.             MyBase.OnMouseUp(e)
  114.         End Sub
  115.  
  116. #End Region
  117.  
  118. #Region "Draw Control"
  119.  
  120.         Sub ReplaceItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
  121.             e.DrawBackground()
  122.             e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  123.             Dim Rect As New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width + 1, e.Bounds.Height + 1)
  124.                 With e.Graphics
  125.                     If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
  126.                         .FillRectangle(New SolidBrush(_SqaureColour), Rect)
  127.                         .DrawString(MyBase.GetItemText(MyBase.Items(e.Index)), Font, New SolidBrush(_FontColour), 1, e.Bounds.Top + 2)
  128.                     Else
  129.                         .FillRectangle(New SolidBrush(_BaseColour), Rect)
  130.                         .DrawString(MyBase.GetItemText(MyBase.Items(e.Index)), Font, New SolidBrush(_FontColour), 1, e.Bounds.Top + 2)
  131.                     End If
  132.                 End With
  133.             e.DrawFocusRectangle()
  134.             Invalidate()
  135.         End Sub
  136.  
  137.         Sub New()
  138.             SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
  139.                    ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or _
  140.                    ControlStyles.SupportsTransparentBackColor, True)
  141.             DoubleBuffered = True
  142.             BackColor = Color.Transparent
  143.             DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
  144.             DropDownStyle = ComboBoxStyle.DropDownList
  145.             Width = 163
  146.             Font = New Font("Segoe UI", 10)
  147.         End Sub
  148.  
  149.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  150.             Dim g = e.Graphics
  151.             With g
  152.                 .TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  153.                 .SmoothingMode = SmoothingMode.HighQuality
  154.                 .PixelOffsetMode = PixelOffsetMode.HighQuality
  155.                 .Clear(BackColor)
  156.  
  157.                 Dim Square As New Rectangle(Width - 25, 0, Width, Height)
  158.                 .FillRectangle(New SolidBrush(_BaseColour), New Rectangle(0, 0, Width - 25, Height))
  159.                 Select Case State
  160.                     Case MouseState.None
  161.                         .FillRectangle(New SolidBrush(_SqaureColour), Square)
  162.                     Case MouseState.Over
  163.                         .FillRectangle(New SolidBrush(_SqaureHoverColour), Square)
  164.                 End Select
  165.                 .DrawLine(New Pen(_LineColour, 2), New Point(Width - 26, 1), New Point(Width - 26, Height - 1))
  166.                 If Me.Parent.Enabled = False Then
  167.                     _FontColour = Color.Gray
  168.                 Else
  169.                     _FontColour = Color.FromArgb(255, 255, 255)
  170.                 End If
  171.                 If SelectedIndex <> -1 Then
  172.                     .DrawString(Text, Font, New SolidBrush(_FontColour), New Rectangle(3, 0, Width - 20, Height), New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})
  173.                 Else
  174.                     If Not Items Is Nothing And Items.Count > 0 Then
  175.                         SelectedIndex = 0
  176.                         .DrawString(Items(0).ToString, Font, New SolidBrush(_FontColour), New Rectangle(3, 0, Width - 20, Height), New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})
  177.                     End If
  178.                 End If
  179.                 .DrawRectangle(New Pen(_BorderColour, 2), New Rectangle(0, 0, Width, Height))
  180.                 Dim P() As Point = {New Point(Width - 17, 11), New Point(Width - 13, 5), New Point(Width - 9, 11)}
  181.                 .FillPolygon(New SolidBrush(_BorderColour), P)
  182.                 .DrawPolygon(New Pen(_ArrowColour), P)
  183.                 Dim P1() As Point = {New Point(Width - 17, 15), New Point(Width - 13, 21), New Point(Width - 9, 15)}
  184.                 .FillPolygon(New SolidBrush(_BorderColour), P1)
  185.                 .DrawPolygon(New Pen(_ArrowColour), P1)
  186.                 .InterpolationMode = CType(7, InterpolationMode)
  187.             End With
  188.  
  189.         End Sub
  190.  
  191. #End Region
  192.  
  193.     End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement