Guest User

Design Functions

a guest
Dec 20th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.70 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. Module DesignFunctions
  4.     Function ToBrush(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
  5.         Return ToBrush(Color.FromArgb(A, R, G, B))
  6.     End Function
  7.     Function ToBrush(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
  8.         Return ToBrush(Color.FromArgb(R, G, B))
  9.     End Function
  10.     Function ToBrush(ByVal A As Integer, ByVal C As Color) As Brush
  11.         Return ToBrush(Color.FromArgb(A, C))
  12.     End Function
  13.     Function ToBrush(ByVal Pen As Pen) As Brush
  14.         Return ToBrush(Pen.Color)
  15.     End Function
  16.     Function ToBrush(ByVal Color As Color) As Brush
  17.         Return New SolidBrush(Color)
  18.     End Function
  19.     Function ToPen(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
  20.         Return ToPen(Color.FromArgb(A, R, G, B))
  21.     End Function
  22.     Function ToPen(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
  23.         Return ToPen(Color.FromArgb(R, G, B))
  24.     End Function
  25.     Function ToPen(ByVal A As Integer, ByVal C As Color) As Pen
  26.         Return ToPen(Color.FromArgb(A, C))
  27.     End Function
  28.     Function ToPen(ByVal Color As Color) As Pen
  29.         Return ToPen(New SolidBrush(Color))
  30.     End Function
  31.     Function ToPen(ByVal Brush As SolidBrush) As Pen
  32.         Return New Pen(Brush)
  33.     End Function
  34.  
  35.     Class CornerStyle
  36.         Public TopLeft As Boolean
  37.         Public TopRight As Boolean
  38.         Public BottomLeft As Boolean
  39.         Public BottomRight As Boolean
  40.     End Class
  41.  
  42.     Public Function AdvRect(ByVal Rectangle As Rectangle, ByVal CornerStyle As CornerStyle, ByVal Curve As Integer) As GraphicsPath
  43.         AdvRect = New GraphicsPath()
  44.         Dim ArcRectangleWidth As Integer = Curve * 2
  45.  
  46.         If CornerStyle.TopLeft Then
  47.             AdvRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  48.         Else
  49.             AdvRect.AddLine(Rectangle.X, Rectangle.Y, Rectangle.X + ArcRectangleWidth, Rectangle.Y)
  50.         End If
  51.  
  52.         If CornerStyle.TopRight Then
  53.             AdvRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  54.         Else
  55.             AdvRect.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + ArcRectangleWidth)
  56.         End If
  57.  
  58.         If CornerStyle.BottomRight Then
  59.             AdvRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  60.         Else
  61.             AdvRect.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height, Rectangle.X + Rectangle.Width - ArcRectangleWidth, Rectangle.Y + Rectangle.Height)
  62.         End If
  63.  
  64.         If CornerStyle.BottomLeft Then
  65.             AdvRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  66.         Else
  67.             AdvRect.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y + Rectangle.Height - ArcRectangleWidth)
  68.         End If
  69.  
  70.         AdvRect.CloseAllFigures()
  71.  
  72.         Return AdvRect
  73.     End Function
  74.  
  75.     Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  76.         RoundRect = New GraphicsPath()
  77.         Dim ArcRectangleWidth As Integer = Curve * 2
  78.         RoundRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  79.         RoundRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  80.         RoundRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  81.         RoundRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  82.         RoundRect.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, ArcRectangleWidth + Rectangle.Y))
  83.         RoundRect.CloseAllFigures()
  84.         Return RoundRect
  85.     End Function
  86.  
  87.     Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
  88.         Return RoundRect(New Rectangle(X, Y, Width, Height), Curve)
  89.     End Function
  90.  
  91.     Class PillStyle
  92.         Public Left As Boolean
  93.         Public Right As Boolean
  94.     End Class
  95.  
  96.     Public Function Pill(ByVal Rectangle As Rectangle, ByVal PillStyle As PillStyle) As GraphicsPath
  97.         Pill = New GraphicsPath()
  98.  
  99.         If PillStyle.Left Then
  100.             Pill.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Height, Rectangle.Height), -270, 180)
  101.         Else
  102.             Pill.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y)
  103.         End If
  104.  
  105.         If PillStyle.Right Then
  106.             Pill.AddArc(New Rectangle(Rectangle.X + Rectangle.Width - Rectangle.Height, Rectangle.Y, Rectangle.Height, Rectangle.Height), -90, 180)
  107.         Else
  108.             Pill.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height)
  109.         End If
  110.  
  111.         Pill.CloseAllFigures()
  112.  
  113.         Return Pill
  114.     End Function
  115.  
  116.     Public Function Pill(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal PillStyle As PillStyle)
  117.         Return Pill(New Rectangle(X, Y, Width, Height), PillStyle)
  118.     End Function
  119.  
  120. End Module
Advertisement
Add Comment
Please, Sign In to add comment