0Hawk0

[VB] Pro Controls

Nov 18th, 2014
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 20.51 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. Class Adjustments
  4.  
  5.     'Default FontFamily that will be used throughout the entire theme
  6.     Public Shared ReadOnly DefaultFontFamily As FontFamily = New FontFamily("Verdana")
  7.  
  8.     'Roundness of the corners of most controls. Higher = more circular
  9.     Public Shared ReadOnly Roundness As Integer = 4
  10.  
  11. End Class
  12.  
  13. Class DrawingHelper
  14.  
  15.     Enum RoundingStyle
  16.         All
  17.         Top
  18.         Bottom
  19.         Left
  20.         Right
  21.     End Enum
  22.  
  23.     Public Function RoundRect(ByVal rect As Rectangle, ByVal slope As Integer, Optional ByVal style As RoundingStyle = RoundingStyle.All) As GraphicsPath
  24.  
  25.         Dim gp As GraphicsPath = New GraphicsPath()
  26.         Dim arcWidth As Integer = slope * 2
  27.  
  28.         Select Case style
  29.             Case RoundingStyle.All
  30.                 gp.AddArc(New Rectangle(rect.X, rect.Y, arcWidth, arcWidth), -180, 90)
  31.                 gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Y, arcWidth, arcWidth), -90, 90)
  32.                 gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 0, 90)
  33.                 gp.AddArc(New Rectangle(rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 90, 90)
  34.             Case RoundingStyle.Top
  35.                 gp.AddArc(New Rectangle(rect.X, rect.Y, arcWidth, arcWidth), -180, 90)
  36.                 gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Y, arcWidth, arcWidth), -90, 90)
  37.                 gp.AddLine(New Point(rect.X + rect.Width, rect.Y + rect.Height), New Point(rect.X, rect.Y + rect.Height))
  38.             Case RoundingStyle.Bottom
  39.                 gp.AddLine(New Point(rect.X, rect.Y), New Point(rect.X + rect.Width, rect.Y))
  40.                 gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 0, 90)
  41.                 gp.AddArc(New Rectangle(rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 90, 90)
  42.             Case RoundingStyle.Left
  43.                 gp.AddArc(New Rectangle(rect.X, rect.Y, arcWidth, arcWidth), -180, 90)
  44.                 gp.AddLine(New Point(rect.X + rect.Width, rect.Y), New Point(rect.X + rect.Width, rect.Y + rect.Height))
  45.                 gp.AddArc(New Rectangle(rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 90, 90)
  46.             Case RoundingStyle.Right
  47.                 gp.AddLine(New Point(rect.X, rect.Y + rect.Height), New Point(rect.X, rect.Y))
  48.                 gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Y, arcWidth, arcWidth), -90, 90)
  49.                 gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 0, 90)
  50.         End Select
  51.  
  52.         gp.CloseAllFigures()
  53.  
  54.         Return gp
  55.  
  56.     End Function
  57.  
  58.     Enum ColorAdjustmentType
  59.         Lighten
  60.         Darken
  61.     End Enum
  62.  
  63.     Public Function AdjustColor(ByVal c As Color, ByVal intensity As Integer, ByVal adjustment As ColorAdjustmentType, Optional ByVal keepAlpha As Boolean = True) As Color
  64.  
  65.         Dim r, g, b As Integer
  66.  
  67.         If intensity < 1 Then
  68.             intensity = 1
  69.         ElseIf intensity > 255 Then
  70.             intensity = 255
  71.         End If
  72.  
  73.         If adjustment = ColorAdjustmentType.Lighten Then
  74.             r = IncrementValue(c.R, intensity)
  75.             g = IncrementValue(c.G, intensity)
  76.             b = IncrementValue(c.B, intensity)
  77.         Else
  78.             r = DecrementValue(c.R, intensity)
  79.             g = DecrementValue(c.G, intensity)
  80.             b = DecrementValue(c.B, intensity)
  81.         End If
  82.  
  83.         If keepAlpha Then
  84.             Return Color.FromArgb(c.A, r, g, b)
  85.         Else
  86.             Return Color.FromArgb(255, r, g, b)
  87.         End If
  88.  
  89.  
  90.     End Function
  91.  
  92.     Private Function IncrementValue(ByVal initialValue As Integer, ByVal intensity As Integer, Optional ByVal maximum As Integer = 255)
  93.         If initialValue + intensity < maximum Then
  94.             Return initialValue + intensity
  95.         Else
  96.             Return maximum
  97.         End If
  98.     End Function
  99.  
  100.     Private Function DecrementValue(ByVal initialValue As Integer, ByVal intensity As Integer, Optional ByVal minimum As Integer = 0)
  101.         If initialValue - intensity > minimum Then
  102.             Return initialValue - intensity
  103.         Else
  104.             Return minimum
  105.         End If
  106.     End Function
  107.  
  108. End Class
  109.  
  110. Class MultiLineHandler
  111.  
  112.     Public Function GetLines(ByVal g As Graphics, ByVal str As String, ByVal font As Font, ByVal maxLength As Integer) As List(Of String)
  113.  
  114.         Dim result As New List(Of String)
  115.         Dim sb As New System.Text.StringBuilder
  116.  
  117.         str = str.Replace(vbCr, "").Replace(vbLf, "")
  118.  
  119.         Dim words As String()
  120.         If str.Contains(" ") Then
  121.             words = str.Replace(Environment.NewLine, Nothing).Split(" ")
  122.         Else
  123.             result.Add(str)
  124.             Return result
  125.         End If
  126.  
  127.         For i = 0 To words.Count - 1
  128.  
  129.             If i = words.Count - 1 Then
  130.                 If g.MeasureString(sb.ToString & " " & words(i), font).Width < maxLength Then
  131.                     sb.Append(words(i))
  132.                     result.Add(sb.ToString())
  133.                 Else
  134.                     result.Add(sb.ToString())
  135.                     result.Add(words(i))
  136.                 End If
  137.             ElseIf g.MeasureString(sb.ToString & " " & words(i), font).Width > maxLength Then
  138.                 result.Add(sb.ToString())
  139.                 sb.Clear()
  140.                 sb.Append(words(i) & " ")
  141.             Else
  142.                 sb.Append(words(i) & " ")
  143.             End If
  144.  
  145.         Next
  146.  
  147.         Return result
  148.  
  149.     End Function
  150.  
  151. End Class
  152.  
  153. Class ProBasicButton
  154.     Inherits Control
  155.  
  156.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  157.         MyBase.OnPaint(e)
  158.  
  159.         Dim g As Graphics = e.Graphics
  160.         g.SmoothingMode = SmoothingMode.HighQuality
  161.         g.Clear(Parent.BackColor)
  162.  
  163.         Dim dh As New DrawingHelper
  164.         Dim slope As Integer = Adjustments.Roundness
  165.  
  166.         Dim mainRect As New Rectangle(2, 0, Width - 5, Height - 1)
  167.         Dim mainPath As GraphicsPath = dh.RoundRect(mainRect, slope)
  168.         Dim backLGB As LinearGradientBrush
  169.         If _scheme = ColorScheme.Orange Then
  170.             backLGB = New LinearGradientBrush(mainRect, Color.FromArgb(255, 120, 0), Color.FromArgb(200, 50, 0), 90.0F)
  171.         Else
  172.             Dim backCB As New ColorBlend(3)
  173.             backCB.Colors = {Color.WhiteSmoke, Color.WhiteSmoke, Color.FromArgb(225, 230, 230)}
  174.             backCB.Positions = {0.0, 0.75, 1.0}
  175.             backLGB = New LinearGradientBrush(mainRect, Color.Black, Color.Black, 90.0F)
  176.             backLGB.InterpolationColors = backCB
  177.         End If
  178.         g.FillPath(backLGB, mainPath)
  179.  
  180.         If _scheme = ColorScheme.Orange Then
  181.             If state = MouseState.Over Then
  182.                 g.FillPath(New SolidBrush(Color.FromArgb(18, Color.White)), mainPath)
  183.             ElseIf state = MouseState.Down Then
  184.                 g.FillPath(New SolidBrush(Color.FromArgb(30, Color.White)), mainPath)
  185.             End If
  186.         Else
  187.             If state = MouseState.Over Then
  188.                 g.FillPath(New SolidBrush(Color.FromArgb(10, Color.Black)), mainPath)
  189.             ElseIf state = MouseState.Down Then
  190.                 g.FillPath(New SolidBrush(Color.FromArgb(18, Color.Black)), mainPath)
  191.             End If
  192.         End If
  193.  
  194.         Dim textX, textY As Integer
  195.         If _image IsNot Nothing Then
  196.             Dim bufferWidth As Integer = 4
  197.             Dim imageSize As New Size(Height - 20, Height - 20)
  198.             Dim imageLocation As Point
  199.             Dim imageRect As Rectangle
  200.             If _alignment = HorizontalAlignment.Left Then
  201.                 imageRect = New Rectangle(New Point(14, 10), imageSize)
  202.                 textX = imageRect.X + imageSize.Width + bufferWidth
  203.             ElseIf _alignment = HorizontalAlignment.Center Then
  204.                 imageLocation = New Point((Width / 2) - (imageSize.Width / 2) - (bufferWidth / 2) - (g.MeasureString(Text, Font).Width / 2), (Height / 2) - (imageSize.Height / 2))
  205.                 imageRect = New Rectangle(imageLocation, imageSize)
  206.                 textX = imageLocation.X + imageSize.Width + bufferWidth
  207.             ElseIf _alignment = HorizontalAlignment.Right Then
  208.                 textX = Width - 14 - g.MeasureString(Text, Font).Width
  209.                 imageRect = New Rectangle(New Point(textX - bufferWidth - imageSize.Width, 10), imageSize)
  210.             End If
  211.             g.DrawImage(_image, imageRect)
  212.         Else
  213.             If _alignment = HorizontalAlignment.Left Then
  214.                 textX = 14
  215.             ElseIf _alignment = HorizontalAlignment.Center Then
  216.                 textX = (Me.Width / 2) - (g.MeasureString(Text, Font).Width / 2)
  217.             ElseIf _alignment = HorizontalAlignment.Right Then
  218.                 textX = Width - g.MeasureString(Text, Font).Width - 14
  219.             End If
  220.         End If
  221.         textY = (Me.Height / 2) - (g.MeasureString(Text, Font).Height / 2) + 1
  222.  
  223.         Dim borderLGB As LinearGradientBrush
  224.         If _scheme = ColorScheme.Orange Then
  225.             g.DrawString(Text, Font, Brushes.WhiteSmoke, New Point(textX, textY))
  226.             borderLGB = New LinearGradientBrush(New Rectangle(0, 0, Width, Height), Color.FromArgb(180, 60, 0), Color.FromArgb(220, 120, 60), 90.0F)
  227.         Else
  228.             g.DrawString(Text, Font, New SolidBrush(Color.FromArgb(50, 50, 50)), New Point(textX, textY))
  229.             borderLGB = New LinearGradientBrush(New Rectangle(0, 0, Width, Height), Color.Silver, Color.Gainsboro, 90.0F)
  230.         End If
  231.  
  232.         g.DrawPath(New Pen(borderLGB), mainPath)
  233.  
  234.     End Sub
  235.  
  236.     Sub New()
  237.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
  238.         Font = New Font(Adjustments.DefaultFontFamily, 10)
  239.         Size = New Size(140, 50)
  240.         Cursor = Cursors.Hand
  241.     End Sub
  242.  
  243.     Private _image As Image
  244.     Public Property Image As Image
  245.         Get
  246.             Return _image
  247.         End Get
  248.         Set(value As Image)
  249.             _image = value
  250.             Invalidate()
  251.         End Set
  252.     End Property
  253.  
  254.     Private _alignment As HorizontalAlignment = HorizontalAlignment.Center
  255.     Public Property TextAlignment As HorizontalAlignment
  256.         Get
  257.             Return _alignment
  258.         End Get
  259.         Set(value As HorizontalAlignment)
  260.             _alignment = value
  261.             Invalidate()
  262.         End Set
  263.     End Property
  264.  
  265.     Enum ColorScheme
  266.         White
  267.         Orange
  268.     End Enum
  269.  
  270.     Private _scheme As ColorScheme = ColorScheme.White
  271.     Public Property Scheme As ColorScheme
  272.         Get
  273.             Return _scheme
  274.         End Get
  275.         Set(value As ColorScheme)
  276.             _scheme = value
  277.             Invalidate()
  278.         End Set
  279.     End Property
  280.  
  281.     Enum MouseState
  282.         None
  283.         Over
  284.         Down
  285.     End Enum
  286.  
  287.     Private state As MouseState = MouseState.None
  288.  
  289.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  290.         MyBase.OnMouseEnter(e)
  291.         state = MouseState.Over
  292.         Invalidate()
  293.     End Sub
  294.  
  295.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  296.         MyBase.OnMouseLeave(e)
  297.         state = MouseState.None
  298.         Invalidate()
  299.     End Sub
  300.  
  301.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  302.         MyBase.OnMouseDown(e)
  303.         state = MouseState.Down
  304.         Invalidate()
  305.     End Sub
  306.  
  307.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  308.         MyBase.OnMouseUp(e)
  309.         state = MouseState.Over
  310.         Invalidate()
  311.     End Sub
  312.  
  313.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  314.         MyBase.OnTextChanged(e)
  315.         Invalidate()
  316.     End Sub
  317.  
  318. End Class
  319.  
  320. Class ProDescriptiveButton
  321.     Inherits Control
  322.  
  323.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  324.         MyBase.OnPaint(e)
  325.  
  326.         Dim g As Graphics = e.Graphics
  327.         g.SmoothingMode = SmoothingMode.HighQuality
  328.         g.Clear(Parent.BackColor)
  329.  
  330.         Dim dh As New DrawingHelper
  331.         Dim mlh As New MultiLineHandler
  332.         Dim slope As Integer = Adjustments.Roundness
  333.  
  334.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  335.         Dim mainPath As GraphicsPath = dh.RoundRect(mainRect, slope)
  336.  
  337.         Dim backCB As New ColorBlend(3)
  338.         backCB.Colors = {Color.WhiteSmoke, Color.WhiteSmoke, Color.FromArgb(225, 230, 230)}
  339.         backCB.Positions = {0.0, 0.75, 1.0}
  340.         Dim backLGB As New LinearGradientBrush(mainRect, Color.Black, Color.Black, 90.0F)
  341.         backLGB.InterpolationColors = backCB
  342.         g.FillPath(backLGB, mainPath)
  343.  
  344.         Dim textBrush As New SolidBrush(Color.FromArgb(50, 50, 50))
  345.  
  346.         If _image IsNot Nothing Then
  347.             Dim imageRect As New Rectangle(12, 12, 48, 48)
  348.             g.DrawImage(_image, imageRect)
  349.             g.DrawString(_title, _titleFont, textBrush, New Point(12 + 48 + 4, 12 + (48 / 2) - (g.MeasureString(_title, _titleFont).Height / 2)))
  350.         Else
  351.             g.DrawString(_title, _titleFont, textBrush, New Point(12, 12 + (48 / 2) - (g.MeasureString(_title, _titleFont).Height / 2)))
  352.         End If
  353.  
  354.         Dim descY As Integer = 12 + 48 + 14
  355.         textBrush = New SolidBrush(Color.FromArgb(120, 120, 120))
  356.  
  357.         For Each line As String In mlh.GetLines(g, Text, Font, Width - 24)
  358.             g.DrawString(line, Font, textBrush, New Point(12, descY))
  359.             descY += 13
  360.         Next
  361.  
  362.         If state = MouseState.Over Then
  363.             g.FillPath(New SolidBrush(Color.FromArgb(10, Color.Black)), mainPath)
  364.         ElseIf state = MouseState.Down Then
  365.             g.FillPath(New SolidBrush(Color.FromArgb(18, Color.Black)), mainPath)
  366.         End If
  367.  
  368.         Dim borderLGB As New LinearGradientBrush(New Rectangle(0, 0, Width, Height), Color.Silver, Color.Gainsboro, 90.0F)
  369.         g.DrawPath(New Pen(borderLGB), mainPath)
  370.  
  371.     End Sub
  372.  
  373.     Sub New()
  374.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
  375.         Font = New Font(Adjustments.DefaultFontFamily, 8)
  376.         Size = New Size(200, 130)
  377.         Cursor = Cursors.Hand
  378.     End Sub
  379.  
  380.     Private _image As Image
  381.     Public Property Image As Image
  382.         Get
  383.             Return _image
  384.         End Get
  385.         Set(value As Image)
  386.             _image = value
  387.             Invalidate()
  388.         End Set
  389.     End Property
  390.  
  391.     Private _title As String = "Title"
  392.     Public Property Title As String
  393.         Get
  394.             Return _title
  395.         End Get
  396.         Set(value As String)
  397.             _title = value
  398.             Invalidate()
  399.         End Set
  400.     End Property
  401.  
  402.     Private _titleFont As Font = New Font(Adjustments.DefaultFontFamily, 14)
  403.     Public Property TitleFont As Font
  404.         Get
  405.             Return _titleFont
  406.         End Get
  407.         Set(value As Font)
  408.             _titleFont = value
  409.             Invalidate()
  410.         End Set
  411.     End Property
  412.  
  413.     Enum MouseState
  414.         None
  415.         Over
  416.         Down
  417.     End Enum
  418.  
  419.     Private state As MouseState = MouseState.None
  420.  
  421.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  422.         MyBase.OnMouseEnter(e)
  423.         state = MouseState.Over
  424.         Invalidate()
  425.     End Sub
  426.  
  427.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  428.         MyBase.OnMouseLeave(e)
  429.         state = MouseState.None
  430.         Invalidate()
  431.     End Sub
  432.  
  433.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  434.         MyBase.OnMouseDown(e)
  435.         state = MouseState.Down
  436.         Invalidate()
  437.     End Sub
  438.  
  439.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  440.         MyBase.OnMouseUp(e)
  441.         state = MouseState.Over
  442.         Invalidate()
  443.     End Sub
  444.  
  445.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  446.         MyBase.OnTextChanged(e)
  447.         Invalidate()
  448.     End Sub
  449.  
  450.     Protected Overrides Sub OnFontChanged(e As EventArgs)
  451.         MyBase.OnFontChanged(e)
  452.         Font = New Font(Font.FontFamily, 8)
  453.     End Sub
  454.  
  455. End Class
  456.  
  457. Class ProMessage
  458.     Inherits Control
  459.  
  460.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  461.         MyBase.OnPaint(e)
  462.  
  463.         Dim g As Graphics = e.Graphics
  464.         g.SmoothingMode = SmoothingMode.HighQuality
  465.         g.Clear(Parent.BackColor)
  466.  
  467.         Dim dh As New DrawingHelper
  468.         Dim mlh As New MultiLineHandler
  469.         Dim slope As Integer = Adjustments.Roundness
  470.  
  471.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  472.         Dim mainPath As GraphicsPath = dh.RoundRect(mainRect, slope)
  473.  
  474.         Dim bgColor, borderColor, textColor As Color
  475.  
  476.         bgColor = dh.AdjustColor(BackColor, 30, DrawingHelper.ColorAdjustmentType.Lighten)
  477.  
  478.         Dim bgCB As New ColorBlend(3)
  479.         bgCB.Colors = {bgColor, bgColor, dh.AdjustColor(bgColor, 15, DrawingHelper.ColorAdjustmentType.Darken)}
  480.         bgCB.Positions = {0.0F, 0.7F, 1.0F}
  481.  
  482.         Dim bgLGB As New LinearGradientBrush(mainRect, Color.Transparent, Color.Transparent, 90.0F)
  483.         bgLGB.InterpolationColors = bgCB
  484.  
  485.         borderColor = dh.AdjustColor(bgColor, 20, DrawingHelper.ColorAdjustmentType.Darken)
  486.         textColor = dh.AdjustColor(bgColor, 95, DrawingHelper.ColorAdjustmentType.Darken)
  487.  
  488.         g.FillPath(bgLGB, mainPath)
  489.         g.DrawPath(New Pen(borderColor), mainPath)
  490.  
  491.         Dim descY As Integer
  492.  
  493.         If Header IsNot Nothing Then
  494.             g.DrawString(_header, _headerFont, New SolidBrush(textColor), New Point(8, 8))
  495.             descY = 8 + g.MeasureString(_header, _headerFont).Height + 6
  496.         Else
  497.             descY = 8
  498.         End If
  499.  
  500.         For Each line As String In mlh.GetLines(g, Text, Font, Width - 16)
  501.             g.DrawString(line, Font, New SolidBrush(textColor), New Point(8, descY))
  502.             descY += 13
  503.         Next
  504.  
  505.         If _sizeByText Then
  506.             Size = New Size(Width, 8 + descY + 4)
  507.         End If
  508.  
  509.     End Sub
  510.  
  511.     Sub New()
  512.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
  513.         BackColor = Color.LightSteelBlue
  514.         Font = New Font(Adjustments.DefaultFontFamily, 8)
  515.         Size = New Size(600, 80)
  516.     End Sub
  517.  
  518.     Private _header As String = "Welcome!"
  519.     Public Property Header As String
  520.         Get
  521.             Return _header
  522.         End Get
  523.         Set(value As String)
  524.             _header = value
  525.             Invalidate()
  526.         End Set
  527.     End Property
  528.  
  529.     Private _headerFont As Font = New Font(Adjustments.DefaultFontFamily, 10, FontStyle.Bold)
  530.     Public Property HeaderFont As Font
  531.         Get
  532.             Return _headerFont
  533.         End Get
  534.         Set(value As Font)
  535.             _headerFont = value
  536.             Invalidate()
  537.         End Set
  538.     End Property
  539.  
  540.     Private _sizeByText As Boolean = False
  541.     Public Property SizeByText As Boolean
  542.         Get
  543.             Return _sizeByText
  544.         End Get
  545.         Set(value As Boolean)
  546.             _sizeByText = value
  547.             Invalidate()
  548.         End Set
  549.     End Property
  550.  
  551.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  552.         MyBase.OnTextChanged(e)
  553.         Invalidate()
  554.     End Sub
  555.  
  556.     Protected Overrides Sub OnFontChanged(e As EventArgs)
  557.         MyBase.OnFontChanged(e)
  558.         Font = New Font(Font.FontFamily, 8)
  559.     End Sub
  560.  
  561. End Class
  562.  
  563. Class ProSeperator
  564.     Inherits Control
  565.  
  566.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  567.         MyBase.OnPaint(e)
  568.  
  569.         Dim g As Graphics = e.Graphics
  570.         g.SmoothingMode = SmoothingMode.HighQuality
  571.         g.Clear(Parent.BackColor)
  572.  
  573.         Dim p1, p2 As Point
  574.         p1 = New Point(0, (Height - 1) / 2)
  575.         p2 = New Point(Width, (Height - 1) / 2)
  576.  
  577.         Dim lineCB As New ColorBlend(3)
  578.         lineCB.Colors = {Color.Transparent, _lineColor, Color.Transparent}
  579.         lineCB.Positions = {0.0F, 0.5F, 1.0F}
  580.  
  581.         Dim lineLGB As New LinearGradientBrush(p1, p2, Color.Transparent, Color.Transparent)
  582.         lineLGB.InterpolationColors = lineCB
  583.  
  584.         g.DrawLine(New Pen(lineLGB), p1, p2)
  585.  
  586.     End Sub
  587.  
  588.     Sub New()
  589.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
  590.         Size = New Size(400, 9)
  591.     End Sub
  592.  
  593.     Private _lineColor As Color = Color.Silver
  594.     Public Property LineColor As Color
  595.         Get
  596.             Return _lineColor
  597.         End Get
  598.         Set(value As Color)
  599.             _lineColor = value
  600.             Invalidate()
  601.         End Set
  602.     End Property
  603.  
  604. End Class
Advertisement
Add Comment
Please, Sign In to add comment