LordPankake

[VB.net] Theme Base

Aug 6th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Drawing.Drawing2D
  2. '|===========================================================|
  3. '|===|  ThemeBase
  4. '| Creator: LordPankake
  5. '| HF Account: http://www.hackforums.net/member.php?action=profile&uid=1828119
  6. '| Created: YY/XX/2014, Last edited: YY/XX/2014
  7. '|===========================================================|
  8. #Region "Base Classes"
  9. Public Class ThemedControl : Inherits Control
  10.     Public D As New DrawUtils
  11.     Public State As MouseState = MouseState.None
  12.     Public Pal As Palette
  13.     Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
  14.     End Sub
  15.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  16.         MyBase.OnMouseEnter(e)
  17.         State = MouseState.Over
  18.         Invalidate()
  19.     End Sub
  20.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  21.         MyBase.OnMouseDown(e)
  22.         State = MouseState.Down
  23.         Invalidate()
  24.     End Sub
  25.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  26.         MyBase.OnMouseLeave(e)
  27.         State = MouseState.None
  28.         Invalidate()
  29.     End Sub
  30.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  31.         MyBase.OnMouseUp(e)
  32.         State = MouseState.Over
  33.         Invalidate()
  34.     End Sub
  35.     Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  36.         MyBase.OnTextChanged(e)
  37.         Invalidate()
  38.     End Sub
  39.     Sub New()
  40.         MyBase.New()
  41.         MinimumSize = New Size(20, 20)
  42.         ForeColor = Color.FromArgb(146, 149, 152)
  43.         Font = New Font("Segoe UI", 10.0F)
  44.         DoubleBuffered = True
  45.         Pal = New Palette
  46.         Pal.ColHighest = Color.FromArgb(150, 150, 153)
  47.         Pal.ColHigh = Color.FromArgb(63, 63, 66)
  48.         Pal.ColMed = Color.FromArgb(35, 35, 37)
  49.         Pal.ColDim = Color.FromArgb(16, 16, 19)
  50.         Pal.ColDark = Color.FromArgb(5, 5, 7)
  51.         BackColor = Pal.ColMed
  52.     End Sub
  53. End Class
  54. Public Class ThemedTextbox : Inherits TextBox
  55.     Public D As New DrawUtils
  56.     Public State As MouseState = MouseState.None
  57.     Public Pal As Palette
  58.     Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
  59.     End Sub
  60.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  61.         MyBase.OnMouseEnter(e)
  62.         State = MouseState.Over
  63.         Invalidate()
  64.     End Sub
  65.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  66.         MyBase.OnMouseDown(e)
  67.         State = MouseState.Down
  68.         Invalidate()
  69.     End Sub
  70.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  71.         MyBase.OnMouseLeave(e)
  72.         State = MouseState.None
  73.         Invalidate()
  74.     End Sub
  75.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  76.         MyBase.OnMouseUp(e)
  77.         State = MouseState.Over
  78.         Invalidate()
  79.     End Sub
  80.     Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  81.         MyBase.OnTextChanged(e)
  82.         Invalidate()
  83.     End Sub
  84.     Sub New()
  85.         MyBase.New()
  86.         MinimumSize = New Size(20, 20)
  87.         ForeColor = Color.FromArgb(146, 149, 152)
  88.         Font = New Font("Segoe UI", 10.0F)
  89.         DoubleBuffered = True
  90.         Pal = New Palette
  91.         Pal.ColHighest = Color.FromArgb(150, 150, 153)
  92.         Pal.ColHigh = Color.FromArgb(63, 63, 66)
  93.         Pal.ColMed = Color.FromArgb(35, 35, 37)
  94.         Pal.ColDim = Color.FromArgb(16, 16, 19)
  95.         Pal.ColDark = Color.FromArgb(5, 5, 7)
  96.         BackColor = Pal.ColMed
  97.     End Sub
  98. End Class
  99. Public Class ThemedContainer : Inherits ContainerControl
  100.     Public D As New DrawUtils
  101.     Public Property Sizable As Boolean = True
  102.     Protected Drag As Boolean = True
  103.     Public State As MouseState = MouseState.None
  104.     Protected TopCap As Boolean = False
  105.     Protected SizeCap As Boolean = False
  106.     Public Pal As Palette
  107.     Protected MouseP As Point = New Point(0, 0)
  108.     Protected TopGrip As Integer
  109.     Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
  110.     End Sub
  111.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  112.         MyBase.OnMouseEnter(e)
  113.         State = MouseState.Over
  114.         Invalidate()
  115.     End Sub
  116.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  117.         MyBase.OnMouseDown(e)
  118.         State = MouseState.Down
  119.         If e.Button = Windows.Forms.MouseButtons.Left Then
  120.             If New Rectangle(0, 0, Width, TopGrip).Contains(e.Location) Then
  121.                 TopCap = True : MouseP = e.Location
  122.             ElseIf Drag And New Rectangle(Width - 15, Height - 15, 15, 15).Contains(e.Location) Then
  123.                 SizeCap = True : MouseP = e.Location
  124.             End If
  125.         End If
  126.     End Sub
  127.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  128.         MyBase.OnMouseLeave(e)
  129.         State = MouseState.None
  130.         Invalidate()
  131.     End Sub
  132.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  133.         MyBase.OnMouseUp(e)
  134.         State = MouseState.Over
  135.         TopCap = False
  136.         If Drag Then
  137.             SizeCap = False
  138.         End If
  139.  
  140.     End Sub
  141.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  142.         MyBase.OnMouseMove(e)
  143.  
  144.         If TopCap Then
  145.             Parent.Location = MousePosition - MouseP
  146.         End If
  147.         If Sizable And Drag And SizeCap Then
  148.             MouseP = e.Location
  149.             Parent.Size = New Size(MouseP)
  150.             Invalidate()
  151.         End If
  152.  
  153.     End Sub
  154.     Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  155.         MyBase.OnTextChanged(e)
  156.         Invalidate()
  157.     End Sub
  158.     Sub New()
  159.         MyBase.New()
  160.         MinimumSize = New Size(20, 20)
  161.         ForeColor = Color.FromArgb(146, 149, 152)
  162.         Font = New Font("Trebuchet MS", 10.0F)
  163.         DoubleBuffered = True
  164.         Pal = New Palette
  165.         Pal.ColHighest = Color.FromArgb(150, 150, 153)
  166.         Pal.ColHigh = Color.FromArgb(63, 63, 66)
  167.         Pal.ColMed = Color.FromArgb(35, 35, 37)
  168.         Pal.ColDim = Color.FromArgb(16, 16, 19)
  169.         Pal.ColDark = Color.FromArgb(5, 5, 7)
  170.         BackColor = Pal.ColMed
  171.     End Sub
  172. End Class
  173. Public Class ThemedTabControl : Inherits TabControl
  174.     Public D As New DrawUtils
  175.     Public State As MouseState = MouseState.None
  176.     Public Pal As Palette
  177.     Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
  178.     End Sub
  179.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  180.         MyBase.OnMouseEnter(e)
  181.         State = MouseState.Over
  182.         Invalidate()
  183.     End Sub
  184.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  185.         MyBase.OnMouseDown(e)
  186.         State = MouseState.Down
  187.         Invalidate()
  188.     End Sub
  189.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  190.         MyBase.OnMouseLeave(e)
  191.         State = MouseState.None
  192.         Invalidate()
  193.     End Sub
  194.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  195.         MyBase.OnMouseUp(e)
  196.         State = MouseState.Over
  197.         Invalidate()
  198.     End Sub
  199.     Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  200.         MyBase.OnTextChanged(e)
  201.         Invalidate()
  202.     End Sub
  203.     Sub New()
  204.         MyBase.New()
  205.         MinimumSize = New Size(20, 20)
  206.         ForeColor = Color.FromArgb(146, 149, 152)
  207.         Font = New Font("Segoe UI", 10.0F)
  208.         DoubleBuffered = True
  209.         Pal = New Palette
  210.         Pal.ColHighest = Color.FromArgb(150, 150, 153)
  211.         Pal.ColHigh = Color.FromArgb(63, 63, 66)
  212.         Pal.ColMed = Color.FromArgb(35, 35, 37)
  213.         Pal.ColDim = Color.FromArgb(16, 16, 19)
  214.         Pal.ColDark = Color.FromArgb(5, 5, 7)
  215.         BackColor = Pal.ColMed
  216.         Alignment = TabAlignment.Top
  217.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
  218.     End Sub
  219. End Class
  220. Public Class ThemedListControl : Inherits listbox
  221.     Public D As New DrawUtils
  222.     Public State As MouseState = MouseState.None
  223.     Public Pal As Palette
  224.     Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
  225.     End Sub
  226.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  227.         MyBase.OnMouseEnter(e)
  228.         State = MouseState.Over
  229.         Invalidate()
  230.     End Sub
  231.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  232.         MyBase.OnMouseDown(e)
  233.         State = MouseState.Down
  234.         Invalidate()
  235.     End Sub
  236.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  237.         MyBase.OnMouseLeave(e)
  238.         State = MouseState.None
  239.         Invalidate()
  240.     End Sub
  241.     Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  242.         MyBase.OnMouseUp(e)
  243.         State = MouseState.Over
  244.         Invalidate()
  245.     End Sub
  246.     Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  247.         MyBase.OnTextChanged(e)
  248.         Invalidate()
  249.     End Sub
  250.     Sub New()
  251.         MyBase.New()
  252.         MinimumSize = New Size(20, 20)
  253.         ForeColor = Color.FromArgb(146, 149, 152)
  254.         Font = New Font("Segoe UI", 10.0F)
  255.         DoubleBuffered = True
  256.         Pal = New Palette
  257.         Pal.ColHighest = Color.FromArgb(150, 150, 153)
  258.         Pal.ColHigh = Color.FromArgb(63, 63, 66)
  259.         Pal.ColMed = Color.FromArgb(35, 35, 37)
  260.         Pal.ColDim = Color.FromArgb(16, 16, 19)
  261.         Pal.ColDark = Color.FromArgb(5, 5, 7)
  262.         BackColor = Pal.ColMed
  263.     End Sub
  264. End Class
  265. #End Region
  266.  
  267. #Region "Theme"
  268. Public Class PEForm : Inherits ThemedContainer
  269.     Sub New()
  270.         MyBase.New()
  271.         MinimumSize = New Size(305, 150)
  272.         Dock = DockStyle.Fill
  273.         TopGrip = 60
  274.         Font = New Font("Segoe UI", 10.0F)
  275.         BackColor = Color.FromArgb(21, 23, 25)
  276.         ForeColor = Color.FromArgb(160, Color.White)
  277.     End Sub
  278.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  279.         Dim G As Graphics = e.Graphics
  280.         MyBase.OnPaint(e)
  281.         Try
  282.             Me.ParentForm.TransparencyKey = Color.Fuchsia
  283.             Me.ParentForm.MinimumSize = MinimumSize
  284.             If Not Me.ParentForm.FormBorderStyle = FormBorderStyle.None Then
  285.                 Me.ParentForm.FormBorderStyle = FormBorderStyle.None
  286.             End If
  287.         Catch ex As Exception : End Try
  288.         G.Clear(Me.ParentForm.TransparencyKey)
  289.  
  290.  
  291.     End Sub
  292. End Class
  293. Public Class PEButton : Inherits ThemedControl
  294.     Sub New()
  295.         MyBase.New()
  296.         Font = New Font("Segoe UI", 11.0F)
  297.     End Sub
  298.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  299.         Dim G As Graphics = e.Graphics
  300.         MyBase.OnPaint(e)
  301.         G.Clear(Me.BackColor)
  302.  
  303.     End Sub
  304. End Class
  305. Public Class PEProgressBar : Inherits ThemedControl
  306.     Private PValue As Integer = 50
  307.     Public Property Value() As Integer
  308.         Get
  309.             Return PValue
  310.         End Get
  311.         Set(ByVal value As Integer)
  312.             PValue = value
  313.             Invalidate()
  314.         End Set
  315.     End Property
  316.     Public Property Minimum As Integer = 0
  317.     Public Property Maximum As Integer = 100
  318.     Sub New()
  319.         MyBase.New()
  320.         Font = New Font("Segoe UI", 11.0F)
  321.     End Sub
  322.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  323.         Dim G As Graphics = e.Graphics
  324.         MyBase.OnPaint(e)
  325.         G.Clear(Me.BackColor)
  326.         Height = 24
  327.  
  328.         Dim MainRect As New Rectangle(0, 0, Width, Height)
  329.         Dim Val As Integer = ValueToPercentage(PValue) * Width - 5
  330.         Dim BarRect As New Rectangle(2, 2, Val, Height - 5)
  331.  
  332.         If Val > 1 Then
  333.  
  334.         End If
  335.     End Sub
  336.     Private Function ValueToPercentage(val As Integer) As Single
  337.         Dim min = Minimum
  338.         Dim max = Maximum
  339.         Return (val - min) / (max - min)
  340.     End Function
  341. End Class
  342. Public Class PECheckbox : Inherits ThemedControl
  343.     Public Property Checked As Boolean
  344.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  345.         MyBase.OnMouseDown(e)
  346.         Checked = Not Checked
  347.         BackColor = Color.FromArgb(21, 23, 25)
  348.     End Sub
  349.     Sub New()
  350.         MyBase.New()
  351.         Font = New Font("Segoe UI", 10.0F)
  352.     End Sub
  353.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  354.         Dim G As Graphics = e.Graphics
  355.         MyBase.OnPaint(e)
  356.         G.Clear(Me.BackColor)
  357.         Height = 20
  358.  
  359.     End Sub
  360. End Class
  361. Public Class PERadiobutton : Inherits ThemedControl
  362.     Public Property Checked As Boolean
  363.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  364.         MyBase.OnMouseDown(e)
  365.         For Each Cont As Control In Parent.Controls
  366.             If TypeOf Cont Is PERadiobutton Then
  367.                 DirectCast(Cont, PERadiobutton).Checked = False
  368.                 Cont.Invalidate()
  369.             End If
  370.         Next
  371.         Checked = True
  372.     End Sub
  373.     Sub New()
  374.         MyBase.New()
  375.         Font = New Font("Segoe UI", 10.0F)
  376.     End Sub
  377.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  378.         Dim G As Graphics = e.Graphics
  379.         MyBase.OnPaint(e)
  380.         G.Clear(Me.BackColor)
  381.         Height = 20
  382.  
  383.     End Sub
  384. End Class
  385. Public Class PEGroupbox : Inherits ThemedContainer
  386.     Public Property TextYOffset As Integer = 2
  387.     Sub New()
  388.         MyBase.New()
  389.         MinimumSize = New Size(10, 10)
  390.         TopGrip = 20
  391.         Font = New Font("Segoe UI", 10.0F)
  392.         BackColor = Color.FromArgb(21, 23, 25)
  393.         ForeColor = Color.FromArgb(160, Color.White)
  394.     End Sub
  395.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  396.         Dim G As Graphics = e.Graphics
  397.         MyBase.OnPaint(e)
  398.         Try
  399.             Me.ParentForm.TransparencyKey = Color.Fuchsia
  400.             Me.ParentForm.MinimumSize = MinimumSize
  401.             If Not Me.ParentForm.FormBorderStyle = FormBorderStyle.None Then
  402.                 Me.ParentForm.FormBorderStyle = FormBorderStyle.None
  403.             End If
  404.         Catch ex As Exception : End Try
  405.         G.Clear(Me.ParentForm.TransparencyKey)
  406.  
  407.     End Sub
  408. End Class
  409. Public Class PETextbox : Inherits ThemedTextbox
  410.     Sub New()
  411.         MyBase.New()
  412.         SetStyle(ControlStyles.UserPaint, True)
  413.         SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
  414.  
  415.         BackColor = Pal.ColDark
  416.         BorderStyle = Windows.Forms.BorderStyle.None
  417.         Multiline = True
  418.         Font = New Font("Segoe UI", 10.0F)
  419.     End Sub
  420.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  421.         Dim G As Graphics = e.Graphics
  422.         MyBase.OnPaint(e)
  423.         If Not Multiline Then
  424.             Height = 21
  425.         End If
  426.         G.Clear(Me.BackColor)
  427.         Height = 20
  428.  
  429.     End Sub
  430. End Class
  431. #End Region
  432.  
  433. #Region "Theme Utility Stuff"
  434. Public Class Palette
  435.     Public ColHighest As Color
  436.     Public ColHigh As Color
  437.     Public ColMed As Color
  438.     Public ColDim As Color
  439.     Public ColDark As Color
  440. End Class
  441. Public Enum ImageMode As Byte
  442.     Normal = 0
  443.     Scaled = 1
  444. End Enum
  445. Public Enum MouseState As Byte
  446.     None = 0
  447.     Over = 1
  448.     Down = 2
  449.     Block = 3
  450. End Enum
  451. Public Enum GradientAlignment As Byte
  452.     Vertical = 0
  453.     Horizontal = 1
  454. End Enum
  455. Public Class DrawUtils
  456.     Public Sub FillGradientBeam(ByVal g As Graphics, ByVal Col1 As Color, ByVal Col2 As Color, ByVal rect As Rectangle, ByVal align As GradientAlignment)
  457.         Dim stored As SmoothingMode = g.SmoothingMode
  458.         Dim Blend As New ColorBlend
  459.         g.SmoothingMode = SmoothingMode.HighQuality
  460.         Select Case align
  461.             Case GradientAlignment.Vertical
  462.                 Dim PathGradient As New LinearGradientBrush(New Point(rect.X, rect.Y), New Point(rect.X + rect.Width - 1, rect.Y), Color.Black, Color.Black)
  463.                 Blend.Positions = {0, 1 / 2, 1}
  464.                 Blend.Colors = {Col1, Col2, Col1}
  465.                 PathGradient.InterpolationColors = Blend
  466.                 g.FillRectangle(PathGradient, rect)
  467.             Case GradientAlignment.Horizontal
  468.                 Dim PathGradient As New LinearGradientBrush(New Point(rect.X, rect.Y), New Point(rect.X, rect.Y + rect.Height), Color.Black, Color.Black)
  469.                 Blend.Positions = {0, 1 / 2, 1}
  470.                 Blend.Colors = {Col1, Col2, Col1}
  471.                 PathGradient.InterpolationColors = Blend
  472.                 PathGradient.RotateTransform(0)
  473.                 g.FillRectangle(PathGradient, rect)
  474.         End Select
  475.         g.SmoothingMode = stored
  476.     End Sub
  477.     Public Sub DrawTextWithShadow(ByVal G As Graphics, ByVal ContRect As Rectangle, ByVal Text As String, ByVal TFont As Font, ByVal TAlign As HorizontalAlignment, ByVal TColor As Color, ByVal BColor As Color)
  478.         DrawText(G, New Rectangle(ContRect.X + 1, ContRect.Y + 1, ContRect.Width, ContRect.Height), Text, TFont, TAlign, BColor)
  479.         DrawText(G, ContRect, Text, TFont, TAlign, TColor)
  480.     End Sub
  481.     Public Sub FillDualGradPath(ByVal g As Graphics, ByVal Col1 As Color, ByVal Col2 As Color, ByVal rect As Rectangle, ByVal gp As GraphicsPath, ByVal align As GradientAlignment)
  482.         Dim stored As SmoothingMode = g.SmoothingMode
  483.         Dim Blend As New ColorBlend
  484.         g.SmoothingMode = SmoothingMode.HighQuality
  485.         Select Case align
  486.             Case GradientAlignment.Vertical
  487.                 Dim PathGradient As New LinearGradientBrush(New Point(rect.X, rect.Y), New Point(rect.X + rect.Width - 1, rect.Y), Color.Black, Color.Black)
  488.                 Blend.Positions = {0, 1 / 2, 1}
  489.                 Blend.Colors = {Col1, Col2, Col1}
  490.                 PathGradient.InterpolationColors = Blend
  491.                 g.FillPath(PathGradient, gp)
  492.             Case GradientAlignment.Horizontal
  493.                 Dim PathGradient As New LinearGradientBrush(New Point(rect.X, rect.Y), New Point(rect.X, rect.Y + rect.Height), Color.Black, Color.Black)
  494.                 Blend.Positions = {0, 1 / 2, 1}
  495.                 Blend.Colors = {Col1, Col2, Col1}
  496.                 PathGradient.InterpolationColors = Blend
  497.                 PathGradient.RotateTransform(0)
  498.                 g.FillPath(PathGradient, gp)
  499.         End Select
  500.         g.SmoothingMode = stored
  501.     End Sub
  502.     Public Sub DrawText(ByVal G As Graphics, ByVal ContRect As Rectangle, ByVal Text As String, ByVal TFont As Font, ByVal TAlign As HorizontalAlignment, ByVal TColor As Color)
  503.         If String.IsNullOrEmpty(Text) Then Return
  504.         Dim TextSize As Size = G.MeasureString(Text, TFont).ToSize
  505.         Dim CenteredY As Integer = ContRect.Height \ 2 - TextSize.Height \ 2
  506.         Select Case TAlign
  507.             Case HorizontalAlignment.Left
  508.                 Dim sf As New StringFormat
  509.                 sf.LineAlignment = StringAlignment.Near
  510.                 sf.Alignment = StringAlignment.Near
  511.                 G.DrawString(Text, TFont, New SolidBrush(TColor), New Rectangle(ContRect.X, ContRect.Y + ContRect.Height / 2 - TextSize.Height / 2, ContRect.Width, ContRect.Height), sf)
  512.             Case HorizontalAlignment.Right
  513.                 Dim sf As New StringFormat
  514.                 sf.LineAlignment = StringAlignment.Far
  515.                 sf.Alignment = StringAlignment.Far
  516.                 G.DrawString(Text, TFont, New SolidBrush(TColor), New Rectangle(ContRect.X, ContRect.Y, ContRect.Width, ContRect.Height / 2 + TextSize.Height / 2), sf)
  517.             Case HorizontalAlignment.Center
  518.                 Dim sf As New StringFormat
  519.                 sf.LineAlignment = StringAlignment.Center
  520.                 sf.Alignment = StringAlignment.Center
  521.                 G.DrawString(Text, TFont, New SolidBrush(TColor), ContRect, sf)
  522.         End Select
  523.     End Sub
  524.     Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  525.         Dim Path As New GraphicsPath
  526.         Dim ArcRectangleWidth As Integer = Curve * 2
  527.         With Path
  528.             .AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  529.             .AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  530.             .AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  531.             .AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  532.             .AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
  533.         End With
  534.         Return Path
  535.     End Function
  536.     Public Function RoundedTopRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  537.         Dim Path As GraphicsPath = New GraphicsPath()
  538.         Dim ArcRectangleWidth As Integer = Curve * 2
  539.         With Path
  540.             .AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  541.             .AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  542.             .AddLine(New Point(Rectangle.X + Rectangle.Width, Rectangle.Y + ArcRectangleWidth), New Point(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height))
  543.             .AddLine(New Point(Rectangle.X, Rectangle.Height + Rectangle.Y), New Point(Rectangle.X, Rectangle.Y + Curve))
  544.         End With
  545.         Return Path
  546.     End Function
  547.     Public Function CodeToImage(ByVal Code As String) As Image
  548.         Return Image.FromStream(New System.IO.MemoryStream(Convert.FromBase64String(Code)))
  549.     End Function
  550. End Class
  551. #End Region
Add Comment
Please, Sign In to add comment