Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public NotInheritable Class Form1 : Inherits Form
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Me.Button1.DrawBorder(Color.Red, 1, ButtonBorderStyle.Solid)
- End Sub
- End Class
- Public Module ControlExtensions
- ''' <summary>
- ''' Draws a solid border of the specified color with 1 pixel width around the bounds of the source <see cref="Control"/>.
- ''' </summary>
- <Extension>
- Public Sub DrawBorder(ByVal sender As Control, ByVal color As Color)
- ControlExtensions.DrawBorder(sender, color, 1, ButtonBorderStyle.Solid, sender.ClientRectangle)
- End Sub
- ''' <summary>
- ''' Draws a solid border of the specified color and with around the bounds of the source <see cref="Control"/>.
- ''' </summary>
- <Extension>
- Public Sub DrawBorder(ByVal sender As Control, ByVal color As Color, ByVal width As Integer)
- ControlExtensions.DrawBorder(sender, color, width, ButtonBorderStyle.Solid, sender.ClientRectangle)
- End Sub
- ''' <summary>
- ''' Draws a border of the specified color, with and style around the bounds of the source <see cref="Control"/>.
- ''' </summary>
- <Extension>
- Public Sub DrawBorder(ByVal sender As Control, ByVal color As Color, ByVal width As Integer, ByVal style As ButtonBorderStyle)
- ControlExtensions.DrawBorder(sender, color, width, style, sender.ClientRectangle)
- End Sub
- ''' <summary>
- ''' Draws a border of the specified color, with and style around the specified bounds of the source <see cref="Control"/>.
- ''' </summary>
- <Extension>
- Public Sub DrawBorder(ByVal sender As Control, ByVal color As Color, ByVal width As Integer, ByVal style As ButtonBorderStyle, ByVal bounds As Rectangle)
- Select Case sender.GetType()
- ' You can add here a custom case for selective painting...
- ' Case GetType(TextBox), GetType(RichTextBox) ' etc.
- Case Else
- Using g As Graphics = sender.CreateGraphics() ' or also: Graphics.FromHwnd(sender.Handle)
- ControlPaint.DrawBorder(g, bounds,
- color, width, style, ' left
- color, width, style, ' top
- color, width, style, ' right
- color, width, style) ' bottom
- End Using
- End Select
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement