Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.ComponentModel
- Imports System.ComponentModel.Design
- Imports System.Drawing.Text
- <System.ComponentModel.Designer(GetType(NButtonDesigner))>
- Friend Class NButton : Inherits Control
- Private _ForeColor As Color = Color.White
- Private _BaseColor As Color = Color.Crimson
- Private _BorderColor As Color = Color.Black
- Public Sub New()
- SetStyle(ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
- DoubleBuffered = True
- UpdateStyles()
- Font = New Font("Segoe UI Light", 10)
- End Sub
- Public Shadows Property ForeColor() As Color
- Get
- Return _ForeColor
- End Get
- Set
- _ForeColor = Value
- Invalidate()
- End Set
- End Property
- Public Property BaseColor() As Color
- Get
- Return _BaseColor
- End Get
- Set
- _BaseColor = Value
- Invalidate()
- End Set
- End Property
- Public Property BorderColor() As Color
- Get
- Return _BorderColor
- End Get
- Set
- _BorderColor = Value
- Invalidate()
- End Set
- End Property
- Protected Overrides Sub OnPaint(pevent As PaintEventArgs)
- Dim g As Graphics = pevent.Graphics
- g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
- Dim r As New Rectangle(0, 0, Width - 1, Height - 1)
- Using BG As New SolidBrush(BaseColor)
- Using F As New SolidBrush(ForeColor)
- Using BD As New Pen(BorderColor)
- Using SF As New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
- g.FillRectangle(BG, r)
- g.DrawRectangle(BD, r)
- g.DrawString(Text, Font, F, r, SF)
- End Using
- End Using
- End Using
- End Using
- End Sub
- End Class
- Friend Class NButtonDesigner : Inherits System.Windows.Forms.Design.ControlDesigner
- Private ReadOnly _PropertiesToStay As String() = {"ForeColor", "BaseColor", "Size", "Location", "BorderColor", "Font", "Name", "Text", "TabIndex"}
- Protected Overrides Sub PostFilterProperties(properties As IDictionary)
- Dim _ListToRemove As New List(Of String)()
- For Each item In properties.Keys
- If Not DirectCast(_PropertiesToStay, IList).Contains(item) Then
- _ListToRemove.Add(item.ToString())
- End If
- Next
- For Each item In _ListToRemove
- properties.Remove(item)
- Next
- MyBase.PostFilterProperties(properties)
- End Sub
- Private actionListCollection As DesignerActionListCollection
- Public Overrides ReadOnly Property ActionLists() As DesignerActionListCollection
- Get
- If actionListCollection Is Nothing Then
- actionListCollection = New DesignerActionListCollection()
- actionListCollection.Add(New NButtonActionList(Component))
- End If
- Return actionListCollection
- End Get
- End Property
- End Class
- Friend Class NButtonActionList : Inherits DesignerActionList
- Private ReadOnly _NButton As NButton
- Public Sub New(component As IComponent)
- MyBase.New(component)
- _NButton = DirectCast(component, NButton)
- End Sub
- Public Property ForeColor() As Color
- Get
- Return _NButton.ForeColor
- End Get
- Set
- _NButton.ForeColor = value
- End Set
- End Property
- Public Property BaseColor() As Color
- Get
- Return _NButton.BaseColor
- End Get
- Set
- _NButton.BaseColor = value
- End Set
- End Property
- Public Property BorderColor() As Color
- Get
- Return _NButton.BorderColor
- End Get
- Set
- _NButton.BorderColor = value
- End Set
- End Property
- Public Property Text() As String
- Get
- Return _NButton.Text
- End Get
- Set
- _NButton.Text = value
- End Set
- End Property
- Public Property Size() As Size
- Get
- Return _NButton.Size
- End Get
- Set
- _NButton.Size = value
- End Set
- End Property
- Public Property Location() As Point
- Get
- Return _NButton.Location
- End Get
- Set
- _NButton.Location = value
- End Set
- End Property
- Public Sub OriginalSize()
- _NButton.Size = New Size(190, 50)
- End Sub
- Public Overrides Function GetSortedActionItems() As DesignerActionItemCollection
- ' Header Name (Appearance)
- ' 1st BaseColor is property name (it must be exist).
- ' 2nd BaseColor is the display name for the property.
- ' Color is the category name we added from above.
- 'Gets or sets the background color." is the description for the property.
- Dim items As New DesignerActionItemCollection() From { _
- New DesignerActionHeaderItem("Appearance"), _
- New DesignerActionPropertyItem("BaseColor", "BaseColor", "Appearance", "Gets or sets the background color."), _
- New DesignerActionPropertyItem("BorderColor", "BorderColor", "Appearance", "Gets or sets the border color."), _
- New DesignerActionPropertyItem("ForeColor", "ForeColor", "Appearance", "Gets or sets the foreground color."), _
- New DesignerActionPropertyItem("Text", "Text", "Appearance", "Gets or sets the text associated with the control."), _
- New DesignerActionHeaderItem("Layout"), _
- 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."), _
- New DesignerActionPropertyItem("Size", "Size", "Layout", "Gets or sets the height and width of the control."), _
- New DesignerActionHeaderItem("Misc"), _
- New DesignerActionMethodItem(Me, "OriginalSize", "Set Original Size", "Misc", "Gets or sets the height and width of the control.") _
- }
- Return items
- End Function
- End Class
Add Comment
Please, Sign In to add comment