FuckFace32

reCAPTCHA Control

Apr 9th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 24.61 KB | None | 0 0
  1. Imports System.ComponentModel, System.Drawing.Drawing2D
  2.  
  3. #Region "Helpers"
  4. ' Just the mouse states.
  5. Enum MouseState As Byte
  6.     None = 0
  7.     Over = 1
  8.     Down = 2
  9.     Block = 3
  10. End Enum
  11.  
  12. ' The buttons
  13. Public Enum reCAPTCHAButtons
  14.     Reload
  15.     Audio
  16.     Help
  17. End Enum
  18.  
  19. ' Credits to ??? for the function.
  20. Module Draw
  21.     Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  22.         Dim P As GraphicsPath = New GraphicsPath()
  23.         Dim ArcRectangleWidth As Integer = Curve * 2
  24.         P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  25.         P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  26.         P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  27.         P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  28.         P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
  29.         Return P
  30.     End Function
  31. End Module
  32. #End Region
  33.  
  34. '------------------
  35. 'The reCAPTCHA Control
  36. 'Creator: FuckFace
  37. 'Version: 1.0
  38. 'Created: 31/01/2014
  39. 'Changed: 14/03/2014
  40. '------------------
  41. <DefaultEvent("ButtonClicked")> Public Class reCAPTCHAControl : Inherits Control
  42.  
  43.     ' !!! ---------------------------------------------------------------------
  44.     ' !!! Change this if you want to another language like "Introduceți textul"
  45.     Public TypeTheText As String = "Type the text"
  46.     ' !!! Change this if you want to another language like "Introduceți textul"
  47.     ' !!! ---------------------------------------------------------------------
  48.  
  49. #Region "Declarations"
  50.     ' The reCAPTCHA logo that is in the right bottom corner.
  51.     Private reCAPTCHAImage As Image = Image.FromStream(New IO.MemoryStream(Convert.FromBase64String("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")))
  52.     ' The reload captcha button.
  53.     Private ReloadButtonImage As Image = Image.FromStream(New IO.MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAMCAYAAABbayygAAAAxUlEQVR42mNgwAPuVOf9xxSsKfj/dvfW/z9fvQDjz5fP///35w+qwicz+///+/cPjn++fP7/39+/YDaKSTDJxzP6/9+pzv//989vuCa4QpB1X+/e/H8lxuc/Lree87KsYAC559ni2f/xeerDicP/wQpvlWXiVHi/vRrsObDV+Ez7/ekjODQYriYFgxUi+/rNrs3/7zWX//985QKYD/IwXCdM0ddb1/9/uXkVrgkUdChWgAS/3bsND3CQdSgmwcDrbRvwuhUAWyrOPFQ2iiUAAAAASUVORK5CYII=")))
  54.     ' The change-to-audio mode button.
  55.     Private AudioButtonImage As Image = Image.FromStream(New IO.MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAYAAACALL/6AAAAN0lEQVR42mNgwAI+Xz7/n4FYAFL879+//yQpxqUBLA5TgI4xFBKjAStNVQ1YnUSypykKVmIiDgB0S7xT2mux1QAAAABJRU5ErkJggg==")))
  56.     ' The help button.
  57.     Private HelpButtonImage As Image = Image.FromStream(New IO.MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAm0lEQVR42mNggII7NQX/3+7e+v/nqxdgDGKDxBiQwZOZ/f///fuHFYPk4CbBBG8WpYIF79YX///98QNcHGwyyAoQ59WmVWBFz5fOgdMwhSA1DCD3gDhfblwBY2QNMIUgNXCFIAyyDmY1sjvBCmFWg/CP50//P1s0C0wjKwRbjeyZj6ePgU0E0cgK4cEECx6Q1SBFyD6GBw+xAQ4AZaAm1MYl0+4AAAAASUVORK5CYII=")))
  58.     ' Booleans that change if the mouse is over them.
  59.     Private OverReloadButton, OverAudioButton, OverHelpButton As Boolean
  60.     ' Mouse state.
  61.     Private State As MouseState = MouseState.None
  62.     ' The Type the text textbox thinghy.
  63.     Private WithEvents TextBox As Windows.Forms.TextBox
  64.     ' The event that handles clicks on the reload/audio/help button.
  65.     Public Event ButtonClicked(ByVal ClickedButton As reCAPTCHAButtons)
  66. #End Region
  67.  
  68. #Region "Properties"
  69.     ' Property helpers.
  70.     Private _MaxLength As Integer = 32767
  71.     Private _ReadOnly As Boolean = True
  72.     Private _Text As String = TypeTheText
  73.     Private _Image As Image
  74.     Private _DrawreCAPTCHALogo As Boolean = True
  75.     Private _DrawReloadButton As Boolean = True
  76.     Private _DrawAudioButton As Boolean = True
  77.     Private _DrawHelpButton As Boolean = True
  78.  
  79.     ' Just the MaxLength property for the textbox.
  80.     <Category("Behaivor")> _
  81.     Property MaxLength As Integer
  82.         Get
  83.             Return _MaxLength
  84.         End Get
  85.         Set(ByVal value As Integer)
  86.             _MaxLength = value
  87.             If TextBox IsNot Nothing Then
  88.                 TextBox.MaxLength = value
  89.             End If
  90.         End Set
  91.     End Property
  92.     ' If this property is set to true then the textbox will be disabled.
  93.     <Category("Behaivor")> _
  94.     Property [ReadOnly] As Boolean
  95.         Get
  96.             Return Not (_ReadOnly)
  97.         End Get
  98.         Set(ByVal value As Boolean)
  99.             _ReadOnly = Not (value)
  100.             If TextBox IsNot Nothing Then
  101.                 TextBox.ReadOnly = value
  102.             End If
  103.         End Set
  104.     End Property
  105.  
  106.     ' This property is the input from the user.
  107.     Public Overrides Property Text As String
  108.         Get
  109.             Return _Text
  110.         End Get
  111.         Set(ByVal value As String)
  112.             _Text = value
  113.         End Set
  114.     End Property
  115.  
  116.     ' This property lets you use an image for the captcha.
  117.     <Category("Appearance")> _
  118.     Public Property Image As Image
  119.         Get
  120.             Return _Image
  121.         End Get
  122.         Set(ByVal value As Image)
  123.             _Image = value
  124.             Invalidate()
  125.         End Set
  126.     End Property
  127.  
  128.     ' The following properties let you choose if you want some stuff to be drawn.
  129.     <Category("Drawing")> _
  130.     Public Property DrawreCAPTCHALogo As Boolean
  131.         Get
  132.             Return _DrawreCAPTCHALogo
  133.         End Get
  134.         Set(ByVal value As Boolean)
  135.             _DrawreCAPTCHALogo = value
  136.             Invalidate()
  137.         End Set
  138.     End Property
  139.     <Category("Drawing")> _
  140.     Public Property DrawReloadButton As Boolean
  141.         Get
  142.             Return _DrawReloadButton
  143.         End Get
  144.         Set(ByVal value As Boolean)
  145.             _DrawReloadButton = value
  146.             Invalidate()
  147.         End Set
  148.     End Property
  149.     <Category("Drawing")> _
  150.     Public Property DrawAudioButton As Boolean
  151.         Get
  152.             Return _DrawAudioButton
  153.         End Get
  154.         Set(ByVal value As Boolean)
  155.             _DrawAudioButton = value
  156.             Invalidate()
  157.         End Set
  158.     End Property
  159.     <Category("Drawing")> _
  160.     Public Property DrawHelpButton As Boolean
  161.         Get
  162.             Return _DrawHelpButton
  163.         End Get
  164.         Set(ByVal value As Boolean)
  165.             _DrawHelpButton = value
  166.             Invalidate()
  167.         End Set
  168.     End Property
  169.  
  170.     Private Sub TextBox_OnBaseTextChanged(ByVal s As Object, ByVal e As EventArgs) Handles TextBox.TextChanged
  171.         Text = TextBox.Text
  172.         ' Hard-coded the Type The Text thinghy.
  173.         If TextBox.Text = Nothing Then
  174.             TextBox.Text = TypeTheText
  175.             TextBox.ForeColor = Color.FromArgb(135, 119, 127)
  176.         ElseIf Not TextBox.Text = TypeTheText Then
  177.             TextBox.Select(TextBox.Text.Length, 0)
  178.             TextBox.Text = TextBox.Text.Replace(TypeTheText, Nothing)
  179.             TextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText)
  180.         End If
  181.     End Sub
  182.     Private Sub TextBox_Enter(ByVal s As Object, ByVal e As EventArgs) Handles TextBox.Enter
  183.         ' Hard-coded the Type The Text thinghy.
  184.         If TextBox.Text = Nothing Or TextBox.Text = TypeTheText Then
  185.             TextBox.Select(0, 0)
  186.         End If
  187.     End Sub
  188.     Private Sub TextBox_OnBaseKeyDown(ByVal s As Object, ByVal e As KeyEventArgs) Handles TextBox.KeyDown
  189.         ' If the user presses CTRL + A, select all the text in the textbox.
  190.         If e.Control AndAlso e.KeyCode = Keys.A Then
  191.             TextBox.SelectAll()
  192.             e.SuppressKeyPress = True
  193.         End If
  194.         ' If the user presses CTRL + C, copy all the text in the textbox.
  195.         If e.Control AndAlso e.KeyCode = Keys.C Then
  196.             TextBox.Copy()
  197.             e.SuppressKeyPress = True
  198.         End If
  199.     End Sub
  200.  
  201.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  202.         MyBase.OnMouseMove(e)
  203.         ' Check if the mouse is over the rounded rectangle that surrounds the buttons.
  204.         If e.X > 188 AndAlso e.X < 212 AndAlso e.Y > 72 AndAlso e.Y < 122 Then
  205.  
  206.  
  207.             ' TO DO: MAKE THIS FAST-DONE SH*T SHORTER AND COMMENT IT BETTER.
  208.  
  209.             ' MouseOver handling for the reload button only.
  210.             If _DrawReloadButton AndAlso _DrawAudioButton AndAlso _DrawHelpButton Then
  211.                 If e.Y <= 89 Then
  212.                     OverReloadButton = True
  213.                     Cursor = Cursors.Hand
  214.                 Else
  215.                     OverReloadButton = False
  216.                     Cursor = Cursors.Default
  217.                 End If
  218.  
  219.                 If e.Y > 89 AndAlso e.Y <= 105 Then
  220.                     OverAudioButton = True
  221.                     Cursor = Cursors.Hand
  222.                 Else
  223.                     OverAudioButton = False
  224.                 End If
  225.  
  226.                 If e.Y > 105 Then
  227.                     OverHelpButton = True
  228.                     Cursor = Cursors.Hand
  229.                 End If
  230.             ElseIf _DrawReloadButton AndAlso Not _DrawAudioButton AndAlso Not _DrawHelpButton Then
  231.                 If e.Y >= 89 AndAlso e.Y <= 105 Then
  232.                     OverReloadButton = True
  233.                     Cursor = Cursors.Hand
  234.                 Else
  235.                     OverReloadButton = False
  236.                     Cursor = Cursors.Default
  237.                 End If
  238.                 ' MouseOver handling for the reload button and the audio button.
  239.             ElseIf _DrawReloadButton AndAlso _DrawAudioButton AndAlso Not _DrawHelpButton Then
  240.                 If e.Y <= 89 Then
  241.                     OverReloadButton = True
  242.                     Cursor = Cursors.Hand
  243.                 Else
  244.                     OverReloadButton = False
  245.                     Cursor = Cursors.Default
  246.                 End If
  247.                 If e.Y > 89 AndAlso e.Y <= 105 Then
  248.                     OverAudioButton = True
  249.                     Cursor = Cursors.Hand
  250.                 Else
  251.                     OverAudioButton = False
  252.                 End If
  253.                 ' MouseOver handling for the reload button and the help button.
  254.             ElseIf _DrawReloadButton AndAlso Not _DrawAudioButton AndAlso _DrawHelpButton Then
  255.                 If e.Y <= 89 Then
  256.                     OverReloadButton = True
  257.                     Cursor = Cursors.Hand
  258.                 Else
  259.                     OverReloadButton = False
  260.                     Cursor = Cursors.Default
  261.                 End If
  262.                 If e.Y > 89 AndAlso e.Y <= 105 Then
  263.                     OverHelpButton = True
  264.                     Cursor = Cursors.Hand
  265.                 Else
  266.                     OverHelpButton = False
  267.                 End If
  268.                 ' MouseOver handling for the audio button only.
  269.             ElseIf Not _DrawReloadButton AndAlso _DrawAudioButton AndAlso Not _DrawHelpButton Then
  270.                 If e.Y >= 89 AndAlso e.Y <= 105 Then
  271.                     OverAudioButton = True
  272.                     Cursor = Cursors.Hand
  273.                 Else
  274.                     OverAudioButton = False
  275.                     Cursor = Cursors.Default
  276.                 End If
  277.                 ' MouseOver handling for the audio button and the help button.
  278.             ElseIf Not _DrawReloadButton AndAlso _DrawAudioButton AndAlso _DrawHelpButton Then
  279.                 If e.Y <= 89 Then
  280.                     OverAudioButton = True
  281.                     Cursor = Cursors.Hand
  282.                 Else
  283.                     OverAudioButton = False
  284.                     Cursor = Cursors.Default
  285.                 End If
  286.  
  287.                 If e.Y > 89 AndAlso e.Y <= 105 Then
  288.                     OverHelpButton = True
  289.                     Cursor = Cursors.Hand
  290.                 Else
  291.                     OverHelpButton = False
  292.                 End If
  293.                 ' MouseOver handling for the help button only.
  294.             ElseIf Not _DrawReloadButton AndAlso Not _DrawAudioButton AndAlso _DrawHelpButton Then
  295.                 If e.Y >= 89 AndAlso e.Y <= 105 Then
  296.                     OverHelpButton = True
  297.                     Cursor = Cursors.Hand
  298.                 Else
  299.                     OverHelpButton = False
  300.                     Cursor = Cursors.Default
  301.                 End If
  302.             End If
  303.         Else
  304.             ' If the mouse is not over the rounded rectangle that surrounds the buttons, set all of them to False.
  305.             OverReloadButton = False
  306.             OverAudioButton = False
  307.             OverHelpButton = False
  308.  
  309.             ' Set the cursor back to Default.
  310.             Cursor = Cursors.Default
  311.         End If
  312.     End Sub
  313.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  314.         MyBase.OnMouseDown(e)
  315.         ' Set the State to Down.
  316.         State = MouseState.Down : Invalidate()
  317.         ' Raise the ButtonClicked event if the mouse is over one button.
  318.         If OverReloadButton Then
  319.             RaiseEvent ButtonClicked(reCAPTCHAButtons.Reload)
  320.         ElseIf OverAudioButton Then
  321.             RaiseEvent ButtonClicked(reCAPTCHAButtons.Audio)
  322.         ElseIf OverHelpButton Then
  323.             RaiseEvent ButtonClicked(reCAPTCHAButtons.Help)
  324.         End If
  325.     End Sub
  326.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  327.         MyBase.OnMouseUp(e)
  328.         ' Set the State to Over and focus the TextBox.
  329.         State = MouseState.Over : TextBox.Focus() : Invalidate()
  330.     End Sub
  331.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  332.         MyBase.OnMouseEnter(e)
  333.         ' Set the State to Over.
  334.         State = MouseState.Over : Invalidate()
  335.     End Sub
  336.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  337.         MyBase.OnMouseLeave(e)
  338.         ' Set the State to None.
  339.         State = MouseState.None : Invalidate()
  340.     End Sub
  341.  
  342.     Protected Overrides Sub OnResize(ByVal e As EventArgs)
  343.         MyBase.OnResize(e)
  344.         ' Just to not let the user resize this.
  345.         Size = New Size(320, 130)
  346.     End Sub
  347.  
  348.     Protected Overrides Sub OnCreateControl()
  349.         MyBase.OnCreateControl()
  350.         ' If the TextBox is not there, add it.
  351.         If Not Controls.Contains(TextBox) Then
  352.             Controls.Add(TextBox)
  353.             Text = TypeTheText
  354.         End If
  355.         ' This will be the ForeColor of the TextBox.
  356.         ForeColor = Color.FromArgb(135, 119, 127)
  357.     End Sub
  358. #End Region
  359.  
  360.     Sub New()
  361.         ' Set some settings of the control. See more info about SetStyle here:
  362.         ' http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles(v=vs.110).aspx
  363.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer _
  364.                  Or ControlStyles.SupportsTransparentBackColor Or ControlStyles.UserPaint, True)
  365.         DoubleBuffered = True
  366.  
  367.         ' Set some settings of the TextBox.
  368.         TextBox = New Windows.Forms.TextBox
  369.         With TextBox
  370.             .BackColor = Color.White
  371.             .BorderStyle = BorderStyle.None
  372.             .Cursor = Cursors.IBeam
  373.             .Enabled = _ReadOnly
  374.             .Font = New Font("Arial", 10)
  375.             .ForeColor = Color.FromArgb(51, 51, 51)
  376.             .Height = 17
  377.             .Location = New Point(18, 84)
  378.             .MaxLength = _MaxLength
  379.             .Text = Text
  380.             .Width = 152
  381.         End With
  382.     End Sub
  383.  
  384.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  385.         MyBase.OnPaint(e)
  386.         Dim Curve As Integer = 4 ' TO DO: Find the right curve.
  387.  
  388.         With e.Graphics
  389.             .Clear(Parent.BackColor)
  390.             .SmoothingMode = SmoothingMode.HighQuality
  391.             .CompositingQuality = CompositingQuality.HighQuality
  392.             If TextBox.Text = TypeTheText Then TextBox.ForeColor = ForeColor
  393.  
  394.             ' Draw the background.
  395.             .FillPath(Brushes.White, RoundRect(New Rectangle(0, 0, 319, 129), Curve))
  396.  
  397.             ' Draw the red gradient.
  398.             .FillPath(New LinearGradientBrush(New Rectangle(3, 3, 313, 123), Color.FromArgb(175, 21, 0) _
  399.                                               , Color.FromArgb(124, 0, 0), 90S) _
  400.                                           , RoundRect(New Rectangle(3, 3, 313, 123), Curve))
  401.  
  402.             ' Draw the reCAPTCHA logo.
  403.             If _DrawreCAPTCHALogo Then .DrawImage(reCAPTCHAImage, 218, 77)
  404.  
  405.             ' Draw the rounded rectangle that surrounds the image.
  406.             .FillPath(Brushes.White, RoundRect(New Rectangle(9, 9, 302, 59), Curve))
  407.             .DrawPath(Pens.White, RoundRect(New Rectangle(9, 9, 302, 59), Curve))
  408.  
  409.             ' TO DO: FIND THE RIGHT SPOT WHERE TO PLACE THE IMAGE.
  410.  
  411.             ' Draw the image/NO IMAGE! text.
  412.             If _Image IsNot Nothing Then
  413.                 .DrawImage(_Image, 11, 11, 300, 57)
  414.             Else
  415.                 .DrawString("NO IMAGE!", New Font("Arial", 32, FontStyle.Bold), Brushes.Red, 38, 15)
  416.             End If
  417.  
  418.             ' Draw the rounded rectangle that surrounds the textbox.
  419.             .FillPath(New SolidBrush(Color.FromArgb(255, 220, 115)), RoundRect(New Rectangle(9, 72, 173, 49), Curve))
  420.  
  421.             ' Draw the contour of the textbox.
  422.             .FillRectangle(New SolidBrush(Color.FromArgb(204, 169, 64)), New Rectangle(17, 83, 153, 17))
  423.  
  424.  
  425.             ' TO DO: MAKE THIS FAST-DONE SH*T SHORTER.
  426.             '--------------------- Drawing the buttons.
  427.             ' Draw all the buttons
  428.             If _DrawReloadButton AndAlso _DrawAudioButton AndAlso _DrawHelpButton Then
  429.                 ' Draw the rounded rectangle that surrounds the buttons.
  430.                 .DrawPath(New Pen(Color.FromArgb(74, 0, 0)), RoundRect(New Rectangle(188, 72, 25, 50), Curve))
  431.                 .FillPath(New SolidBrush(Color.FromArgb(202, 52, 33)), RoundRect(New Rectangle(189, 73, 23, 48), Curve))
  432.  
  433.                 ' Draw the lines between the buttons.
  434.                 .DrawLine(New Pen(Color.FromArgb(141, 36, 23)), 189, 89, 212, 89)
  435.                 .DrawLine(New Pen(Color.FromArgb(141, 36, 23)), 189, 105, 212, 105)
  436.  
  437.                 ' Draw the buttons themselves.
  438.                 .DrawImage(ReloadButtonImage, 197, 75, 10, 12)
  439.                 .DrawImage(AudioButtonImage, 197, 93, 12, 10)
  440.                 .DrawImage(HelpButtonImage, 197, 109, 10, 10)
  441.  
  442.                 ' Draw only the reload button.
  443.             ElseIf _DrawReloadButton AndAlso Not _DrawAudioButton AndAlso Not _DrawHelpButton Then
  444.                 ' Draw the rounded rectangle that surrounds the button.
  445.                 .DrawPath(New Pen(Color.FromArgb(74, 0, 0)), RoundRect(New Rectangle(188, 89, 25, 18), Curve))
  446.                 .FillPath(New SolidBrush(Color.FromArgb(202, 52, 33)), RoundRect(New Rectangle(189, 90, 23, 16), Curve))
  447.  
  448.                 ' Draw the button itself.
  449.                 .DrawImage(ReloadButtonImage, 197, 93, 10, 12)
  450.  
  451.                 ' Draw the reload button and the audio button.
  452.             ElseIf _DrawReloadButton AndAlso _DrawAudioButton AndAlso Not _DrawHelpButton Then
  453.                 ' Draw the rounded rectangle that surrounds the buttons.
  454.                 .DrawPath(New Pen(Color.FromArgb(74, 0, 0)), RoundRect(New Rectangle(188, 72, 25, 35), Curve))
  455.                 .FillPath(New SolidBrush(Color.FromArgb(202, 52, 33)), RoundRect(New Rectangle(189, 73, 23, 33), Curve))
  456.  
  457.                 ' Draw the lines between the buttons.
  458.                 .DrawLine(New Pen(Color.FromArgb(141, 36, 23)), 189, 89, 212, 89)
  459.  
  460.                 ' Draw the buttons themselves.
  461.                 .DrawImage(ReloadButtonImage, 197, 75, 10, 12)
  462.                 .DrawImage(AudioButtonImage, 197, 93, 12, 10)
  463.  
  464.                 ' Draw the reload button and the help button.
  465.             ElseIf _DrawReloadButton AndAlso Not _DrawAudioButton AndAlso _DrawHelpButton Then
  466.                 ' Draw the rounded rectangle that surrounds the buttons.
  467.                 .DrawPath(New Pen(Color.FromArgb(74, 0, 0)), RoundRect(New Rectangle(188, 72, 25, 35), Curve))
  468.                 .FillPath(New SolidBrush(Color.FromArgb(202, 52, 33)), RoundRect(New Rectangle(189, 73, 23, 33), Curve))
  469.  
  470.                 ' Draw the lines between the buttons.
  471.                 .DrawLine(New Pen(Color.FromArgb(141, 36, 23)), 189, 89, 212, 89)
  472.  
  473.                 ' Draw the buttons themselves.
  474.                 .DrawImage(ReloadButtonImage, 197, 75, 10, 12)
  475.                 .DrawImage(HelpButtonImage, 197, 93, 10, 10)
  476.  
  477.                 ' Draw only the audio button.
  478.             ElseIf Not _DrawReloadButton AndAlso _DrawAudioButton AndAlso Not _DrawHelpButton Then
  479.                 ' Draw the rounded rectangle that surrounds the button.
  480.                 .DrawPath(New Pen(Color.FromArgb(74, 0, 0)), RoundRect(New Rectangle(188, 89, 25, 18), Curve))
  481.                 .FillPath(New SolidBrush(Color.FromArgb(202, 52, 33)), RoundRect(New Rectangle(189, 90, 23, 16), Curve))
  482.  
  483.                 ' Draw the button itself.
  484.                 .DrawImage(AudioButtonImage, 197, 93, 12, 10)
  485.  
  486.                 ' Draw the audio button and the help button
  487.             ElseIf Not _DrawReloadButton AndAlso _DrawAudioButton AndAlso _DrawHelpButton Then
  488.                 ' Draw the rounded rectangle that surrounds the buttons.
  489.                 .DrawPath(New Pen(Color.FromArgb(74, 0, 0)), RoundRect(New Rectangle(188, 72, 25, 35), Curve))
  490.                 .FillPath(New SolidBrush(Color.FromArgb(202, 52, 33)), RoundRect(New Rectangle(189, 73, 23, 33), Curve))
  491.  
  492.                 ' Draw the lines between the buttons.
  493.                 .DrawLine(New Pen(Color.FromArgb(141, 36, 23)), 189, 89, 212, 89)
  494.  
  495.                 ' Draw the buttons themselves.
  496.                 .DrawImage(AudioButtonImage, 197, 75, 12, 10)
  497.                 .DrawImage(HelpButtonImage, 197, 93, 10, 10)
  498.  
  499.                 ' Draw only the help button.
  500.             ElseIf Not _DrawReloadButton AndAlso Not _DrawAudioButton AndAlso _DrawHelpButton Then
  501.                 .DrawPath(New Pen(Color.FromArgb(74, 0, 0)), RoundRect(New Rectangle(188, 89, 25, 18), Curve))
  502.                 .FillPath(New SolidBrush(Color.FromArgb(202, 52, 33)), RoundRect(New Rectangle(189, 90, 23, 16), Curve))
  503.  
  504.                 ' Draw the button itself.
  505.                 .DrawImage(HelpButtonImage, 197, 93, 10, 10)
  506.             End If
  507.         End With
  508.     End Sub
  509. End Class
Add Comment
Please, Sign In to add comment