THE_LORD

NButton

Sep 6th, 2017
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.74 KB | None | 0 0
  1. Imports System.ComponentModel
  2. Imports System.ComponentModel.Design
  3. Imports System.Drawing.Text
  4.  
  5. <System.ComponentModel.Designer(GetType(NButtonDesigner))>
  6. Friend Class NButton : Inherits Control
  7.     Private _ForeColor As Color = Color.White
  8.     Private _BaseColor As Color = Color.Crimson
  9.     Private _BorderColor As Color = Color.Black
  10.  
  11.     Public Sub New()
  12.         SetStyle(ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  13.         DoubleBuffered = True
  14.         UpdateStyles()
  15.         Font = New Font("Segoe UI Light", 10)
  16.     End Sub
  17.  
  18.     Public Shadows Property ForeColor() As Color
  19.         Get
  20.             Return _ForeColor
  21.         End Get
  22.         Set
  23.             _ForeColor = Value
  24.             Invalidate()
  25.         End Set
  26.     End Property
  27.  
  28.     Public Property BaseColor() As Color
  29.         Get
  30.             Return _BaseColor
  31.         End Get
  32.         Set
  33.             _BaseColor = Value
  34.             Invalidate()
  35.         End Set
  36.     End Property
  37.  
  38.     Public Property BorderColor() As Color
  39.         Get
  40.             Return _BorderColor
  41.         End Get
  42.         Set
  43.             _BorderColor = Value
  44.             Invalidate()
  45.         End Set
  46.     End Property
  47.  
  48.     Protected Overrides Sub OnPaint(pevent As PaintEventArgs)
  49.         Dim g As Graphics = pevent.Graphics
  50.         g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  51.         Dim r As New Rectangle(0, 0, Width - 1, Height - 1)
  52.  
  53.         Using BG As New SolidBrush(BaseColor)
  54.             Using F As New SolidBrush(ForeColor)
  55.                 Using BD As New Pen(BorderColor)
  56.                     Using SF As New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
  57.                         g.FillRectangle(BG, r)
  58.                         g.DrawRectangle(BD, r)
  59.                         g.DrawString(Text, Font, F, r, SF)
  60.                     End Using
  61.                 End Using
  62.             End Using
  63.         End Using
  64.     End Sub
  65.  
  66. End Class
  67.  
  68. Friend Class NButtonDesigner : Inherits System.Windows.Forms.Design.ControlDesigner
  69.     Private ReadOnly _PropertiesToStay As String() = {"ForeColor", "BaseColor", "Size", "Location", "BorderColor", "Font", "Name", "Text", "TabIndex"}
  70.  
  71.     Protected Overrides Sub PostFilterProperties(properties As IDictionary)
  72.         Dim _ListToRemove As New List(Of String)()
  73.  
  74.         For Each item In properties.Keys
  75.             If Not DirectCast(_PropertiesToStay, IList).Contains(item) Then
  76.                 _ListToRemove.Add(item.ToString())
  77.             End If
  78.         Next
  79.  
  80.         For Each item In _ListToRemove
  81.             properties.Remove(item)
  82.         Next
  83.         MyBase.PostFilterProperties(properties)
  84.     End Sub
  85.  
  86.     Private actionListCollection As DesignerActionListCollection
  87.  
  88. Public Overrides ReadOnly Property ActionLists() As DesignerActionListCollection
  89.     Get
  90.         If actionListCollection Is Nothing Then
  91.             actionListCollection = New DesignerActionListCollection()
  92.             actionListCollection.Add(New NButtonActionList(Component))
  93.         End If
  94.  
  95.         Return actionListCollection
  96.     End Get
  97. End Property
  98.  
  99.  
  100. End Class
  101.  
  102. Friend Class NButtonActionList : Inherits DesignerActionList
  103.  
  104.     Private ReadOnly _NButton As NButton
  105.  
  106.     Public Sub New(component As IComponent)
  107.         MyBase.New(component)
  108.         _NButton = DirectCast(component, NButton)
  109.     End Sub
  110.  
  111.     Public Property ForeColor() As Color
  112.     Get
  113.         Return _NButton.ForeColor
  114.     End Get
  115.     Set
  116.         _NButton.ForeColor = value
  117.     End Set
  118. End Property
  119.  
  120. Public Property BaseColor() As Color
  121.     Get
  122.         Return _NButton.BaseColor
  123.     End Get
  124.     Set
  125.         _NButton.BaseColor = value
  126.     End Set
  127. End Property
  128.  
  129. Public Property BorderColor() As Color
  130.     Get
  131.         Return _NButton.BorderColor
  132.     End Get
  133.     Set
  134.         _NButton.BorderColor = value
  135.     End Set
  136. End Property
  137.  
  138. Public Property Text() As String
  139.     Get
  140.         Return _NButton.Text
  141.     End Get
  142.     Set
  143.         _NButton.Text = value
  144.     End Set
  145. End Property
  146.  
  147. Public Property Size() As Size
  148.     Get
  149.         Return _NButton.Size
  150.     End Get
  151.     Set
  152.         _NButton.Size = value
  153.     End Set
  154. End Property
  155.  
  156. Public Property Location() As Point
  157.     Get
  158.         Return _NButton.Location
  159.     End Get
  160.     Set
  161.         _NButton.Location = value
  162.     End Set
  163. End Property
  164.  
  165.  
  166. Public Sub OriginalSize()
  167.     _NButton.Size = New Size(190, 50)
  168. End Sub
  169.  
  170.     Public Overrides Function GetSortedActionItems() As DesignerActionItemCollection
  171.         ' Header Name (Appearance)
  172.         ' 1st BaseColor is property name (it must be exist).
  173.         ' 2nd BaseColor is the display name for the property.
  174.         ' Color is the category name we added from above.
  175.         'Gets or sets the background color."  is the description for the property.
  176.  
  177.  
  178.  
  179.     Dim items As New DesignerActionItemCollection() From { _
  180.         New DesignerActionHeaderItem("Appearance"), _
  181.         New DesignerActionPropertyItem("BaseColor", "BaseColor", "Appearance", "Gets or sets the background color."), _
  182.         New DesignerActionPropertyItem("BorderColor", "BorderColor", "Appearance", "Gets or sets the border color."), _
  183.         New DesignerActionPropertyItem("ForeColor", "ForeColor", "Appearance", "Gets or sets the foreground color."), _
  184.         New DesignerActionPropertyItem("Text", "Text", "Appearance", "Gets or sets the text associated with the control."), _
  185.         New DesignerActionHeaderItem("Layout"), _
  186.         New DesignerActionPropertyItem("Location", "Location", "Layout", "Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container."), _
  187.         New DesignerActionPropertyItem("Size", "Size", "Layout", "Gets or sets the height and width of the control."), _
  188.         New DesignerActionHeaderItem("Misc"), _
  189.         New DesignerActionMethodItem(Me, "OriginalSize", "Set Original Size", "Misc", "Gets or sets the height and width of the control.") _
  190.     }
  191.  
  192.     Return items
  193. End Function
  194.  
  195. End Class
Add Comment
Please, Sign In to add comment