Advertisement
netrosly

Ausologic Button - GDI

Feb 1st, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 16.07 KB | None | 0 0
  1. 'Random Controls: Ausologic Button
  2. 'by Nettro ;P
  3.  
  4. Imports System.Drawing.Drawing2D
  5. Public Class AusogicButton
  6.     Inherits Panel
  7.     Property Display_Image As Boolean = False
  8.     Property Texxt As String = "HELP"
  9.     Property Type As Typ
  10.     Enum Typ
  11.         Green
  12.         White
  13.         Orange
  14.     End Enum
  15.     Property Img As Image
  16.     Sub New()
  17.         Me.DoubleBuffered = True
  18.     End Sub
  19. #Region "Functions"
  20.     Public Sub DrawRoundRect(g As Graphics, p As Pen, x As Single, y As Single, width As Single, height As Single, _
  21.       radius As Single)
  22.         Dim gp As New GraphicsPath()
  23.  
  24.         gp.AddLine(x + radius, y, x + width - (radius * 2), y)
  25.         ' Line
  26.         gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90)
  27.         ' Corner
  28.         gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2))
  29.         ' Line
  30.         gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90)
  31.         ' Corner
  32.         gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height)
  33.         ' Line
  34.         gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90)
  35.         ' Corner
  36.         gp.AddLine(x, y + height - (radius * 2), x, y + radius)
  37.         ' Line
  38.         gp.AddArc(x, y, radius * 2, radius * 2, 180, 90)
  39.         ' Corner
  40.         gp.CloseFigure()
  41.  
  42.         g.DrawPath(p, gp)
  43.         gp.Dispose()
  44.     End Sub
  45.     Public Sub FillRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  46.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  47.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
  48.         g.FillPie(b, r.X, r.Y, d, d, 180, 90)
  49.         g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90)
  50.         g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  51.         g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  52.         g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  53.         g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  54.         g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  55.         g.SmoothingMode = mode
  56.     End Sub
  57.     Public Sub FillNotTopRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  58.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  59.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
  60.         g.FillPie(b, r.X, r.Y, 1, 1, 180, 90)
  61.         g.FillPie(b, r.X + r.Width - d, r.Y, 1, 1, 270, 90)
  62.         g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  63.         g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  64.         ' g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  65.         g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  66.         g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  67.         g.SmoothingMode = mode
  68.     End Sub
  69.     Public Sub FillNotBottomRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  70.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  71.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
  72.         g.FillPie(b, r.X, r.Y, d, d, 180, 90)
  73.         g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90)
  74.         'g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  75.         '  g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  76.         g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  77.         ' g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  78.         '   g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  79.         g.SmoothingMode = mode
  80.     End Sub
  81. #End Region
  82.     Private Sub Buttonn_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  83.         e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
  84.         If Type = Typ.Green Then
  85.             If Clicked = True Then
  86.                 FillRoundedRectangle(e.Graphics, New Rectangle(1, 1, Me.Width - 3, Me.Height - 3), 4, New SolidBrush(Color.FromArgb(144, 207, 105)))
  87.                 DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(67, 154, 45)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  88.                 Dim rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  89.                 Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(70, 158, 47), Color.FromArgb(94, 191, 65), 90.0!)
  90.                 e.Graphics.FillRectangle(brushs, rect)
  91.                 rect = New Rectangle(4, 3, Me.Width - 9, Me.Height - 9)
  92.                 e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(17, 137, 39)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  93.                 rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  94.                 e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(255, 255, 255)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  95.                 If Display_Image = True Then
  96.                     e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  97.                 End If
  98.  
  99.             Else
  100.  
  101.                 If MouseHoverr = False Then
  102.                     FillRoundedRectangle(e.Graphics, New Rectangle(1, 1, Me.Width - 3, Me.Height - 3), 4, New SolidBrush(Color.FromArgb(144, 207, 105)))
  103.                     DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(67, 154, 45)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  104.                     Dim rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  105.                     Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(94, 191, 65), Color.FromArgb(70, 158, 47), 90.0!)
  106.                     e.Graphics.FillRectangle(brushs, rect)
  107.                     rect = New Rectangle(4, 3, Me.Width - 9, Me.Height - 9)
  108.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(17, 137, 39)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  109.                     rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  110.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(255, 255, 255)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  111.                     If Display_Image = True Then
  112.                         e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  113.                     End If
  114.  
  115.                 Else
  116.                     FillRoundedRectangle(e.Graphics, New Rectangle(1, 1, Me.Width - 3, Me.Height - 3), 4, New SolidBrush(Color.FromArgb(144, 207, 105)))
  117.                     DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(67, 154, 45)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  118.                     Dim rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  119.                     Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(105, 218, 71), Color.FromArgb(68, 181, 47), 90.0!)
  120.                     e.Graphics.FillRectangle(brushs, rect)
  121.                     rect = New Rectangle(4, 3, Me.Width - 9, Me.Height - 9)
  122.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(17, 137, 39)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  123.                     rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  124.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(255, 255, 255)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  125.                     If Display_Image = True Then
  126.                         e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  127.                     End If
  128.  
  129.                 End If
  130.  
  131.             End If
  132.         ElseIf Type = Typ.Orange Then
  133.             If Clicked = True Then
  134.                 FillRoundedRectangle(e.Graphics, New Rectangle(1, 1, Me.Width - 3, Me.Height - 3), 4, New SolidBrush(Color.FromArgb(255, 201, 66)))
  135.                 DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(237, 126, 0)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  136.                 Dim rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  137.                 Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(255, 137, 0), Color.FromArgb(255, 182, 0), 90.0!)
  138.                 e.Graphics.FillRectangle(brushs, rect)
  139.                 rect = New Rectangle(4, 3, Me.Width - 9, Me.Height - 9)
  140.                 e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(219, 137, 10)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  141.                 rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  142.                 e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(255, 255, 255)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  143.                 If Display_Image = True Then
  144.                     e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  145.                 End If
  146.  
  147.             Else
  148.  
  149.                 If MouseHoverr = False Then
  150.                     FillRoundedRectangle(e.Graphics, New Rectangle(1, 1, Me.Width - 3, Me.Height - 3), 4, New SolidBrush(Color.FromArgb(255, 201, 66)))
  151.                     DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(237, 126, 0)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  152.                     Dim rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  153.                     Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(255, 182, 0), Color.FromArgb(255, 137, 0), 90.0!)
  154.                     e.Graphics.FillRectangle(brushs, rect)
  155.                     rect = New Rectangle(4, 3, Me.Width - 9, Me.Height - 9)
  156.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(219, 137, 10)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  157.                     rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  158.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(255, 255, 255)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  159.                     If Display_Image = True Then
  160.                         e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  161.                     End If
  162.  
  163.                 Else
  164.                     FillRoundedRectangle(e.Graphics, New Rectangle(1, 1, Me.Width - 3, Me.Height - 3), 4, New SolidBrush(Color.FromArgb(255, 201, 66)))
  165.                     DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(237, 126, 0)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  166.                     Dim rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  167.                     Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(255, 202, 0), Color.FromArgb(255, 167, 0), 90.0!)
  168.                     e.Graphics.FillRectangle(brushs, rect)
  169.                     rect = New Rectangle(4, 3, Me.Width - 9, Me.Height - 9)
  170.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(219, 137, 10)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  171.                     rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  172.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Bold), New SolidBrush(Color.FromArgb(255, 255, 255)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  173.                     If Display_Image = True Then
  174.                         e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  175.                     End If
  176.  
  177.                 End If
  178.  
  179.             End If
  180.         ElseIf Type = Typ.White Then
  181.             If Clicked = True Then
  182.                 Dim rect = New Rectangle(1, 1, Me.Width - 3, Me.Height - 3)
  183.                 Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(70, 159, 155, 149), Color.FromArgb(249, 249, 249), 90.0!)
  184.                 FillRoundedRectangle(e.Graphics, rect, 4, brushs)
  185.                 DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(190, 185, 179)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  186.                 e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Regular), New SolidBrush(Color.FromArgb(76, 76, 73)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  187.                 If Display_Image = True Then
  188.                     e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  189.                 End If
  190.  
  191.             Else
  192.  
  193.                 If MouseHoverr = False Then
  194.                     FillRoundedRectangle(e.Graphics, New Rectangle(1, 1, Me.Width - 3, Me.Height - 3), 4, New SolidBrush(Color.FromArgb(249, 249, 249)))
  195.                     DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(190, 185, 179)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  196.                     Dim rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  197.                     Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(250, 250, 249), Color.FromArgb(231, 229, 226), 90.0!)
  198.                     e.Graphics.FillRectangle(brushs, rect)
  199.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Regular), New SolidBrush(Color.FromArgb(76, 76, 73)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  200.                     If Display_Image = True Then
  201.                         e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  202.                     End If
  203.  
  204.                 Else
  205.                     FillRoundedRectangle(e.Graphics, New Rectangle(1, 1, Me.Width - 3, Me.Height - 3), 4, New SolidBrush(Color.FromArgb(249, 249, 249)))
  206.                     DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(190, 185, 179)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  207.                     Dim rect = New Rectangle(4, 4, Me.Width - 9, Me.Height - 9)
  208.                     Dim brushs = New LinearGradientBrush(rect, Color.FromArgb(250, 250, 249), Color.FromArgb(241, 239, 236), 90.0!)
  209.                     e.Graphics.FillRectangle(brushs, rect)
  210.                     e.Graphics.DrawString(Texxt, New Font("Arial", 14, FontStyle.Regular), New SolidBrush(Color.FromArgb(76, 76, 73)), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  211.                     If Display_Image = True Then
  212.                         e.Graphics.DrawImage(Img, New Rectangle(8, 8, 32, 32))
  213.                     End If
  214.  
  215.                 End If
  216.  
  217.             End If
  218.         End If
  219.         Clicked = False
  220.     End Sub
  221. #Region "ThemeDraggable"
  222.     Property Clicked As Boolean = False
  223.     Event Clickedd()
  224.  
  225.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  226.         If New Rectangle(1, 1, Me.Width - 3, Me.Height - 3).Contains(e.X, e.Y) Then
  227.             Clicked = True
  228.             RaiseEvent Clickedd()
  229.             Me.Refresh()
  230.         End If
  231.         '
  232.         MyBase.OnMouseDown(e)
  233.     End Sub
  234.  
  235.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  236.  
  237.         MyBase.OnMouseUp(e)
  238.     End Sub
  239.  
  240.     Private mouseX As Integer
  241.     Private mouseY As Integer
  242.     Property MouseHoverr As Boolean = False
  243.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  244.  
  245.         mouseX = e.X
  246.         mouseY = e.Y
  247.         If New Rectangle(2, 2, Me.Width - 4, Me.Height - 4).Contains(e.X, e.Y) Then
  248.             MouseHoverr = True
  249.         Else
  250.             MouseHoverr = False
  251.         End If
  252.         MyBase.OnMouseMove(e)
  253.         Invalidate()
  254.     End Sub
  255.  
  256. #End Region
  257. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement