Advertisement
Guest User

inherited button class with custom border color - by elektro

a guest
Jun 25th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.33 KB | None | 0 0
  1. <DisplayName("MyExtendedButton")>
  2. <Description("A extended Button control.")>
  3. <DesignTimeVisible(True)>
  4. <DesignerCategory("UserControl")>
  5. <ToolboxBitmap(GetType(Button), "Button.bmp")>
  6. <ToolboxItemFilter("System.Windows.Forms", ToolboxItemFilterType.Require)>
  7. <ClassInterface(ClassInterfaceType.AutoDispatch)>
  8. <ComVisible(True)>
  9. <DefaultProperty("Text")>
  10. <DefaultEvent("Click")>
  11. Public NotInheritable Class MyButton : Inherits Button
  12.  
  13.     <Browsable(True)>
  14.     <EditorBrowsable(EditorBrowsableState.Always)>
  15.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  16.     <Localizable(False)>
  17.     <Description("The border color of the control.")>
  18.     <DefaultValue(GetType(Color), "ControlLight")>
  19.     Public Property BorderColor As Color = Color.Red
  20.  
  21.     <DebuggerNonUserCode>
  22.     Public Sub New()
  23.  
  24.         MyBase.SuspendLayout()
  25.  
  26.         MyBase.SetStyle(ControlStyles.DoubleBuffer, True)
  27.         ' MyBase.SetStyle(ControlStyles.AllPaintingInWmPaint, ...)
  28.         ' MyBase.SetStyle(ControlStyles.ResizeRedraw, ...)
  29.         ' MyBase.SetStyle(ControlStyles.UserPaint, ...)
  30.         ' MyBase.SetStyle(ControlStyles.SupportsTransparentBackColor, ...)
  31.  
  32.         MyBase.ResumeLayout(performLayout:=False)
  33.  
  34.     End Sub
  35.  
  36.     <DebuggerStepThrough>
  37.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  38.         MyBase.OnPaint(e)
  39.     End Sub
  40.  
  41.     <DebuggerStepThrough>
  42.     Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
  43.         MyBase.OnPaintBackground(e)
  44.     End Sub
  45.  
  46.     <DebuggerStepperBoundary>
  47.     Protected Overrides Sub WndProc(ByRef m As Message)
  48.  
  49.         MyBase.WndProc(m)
  50.  
  51.         Select Case m.Msg
  52.             Case 15 ' WM_Paint
  53.                 Me.DrawBorder()
  54.         End Select
  55.  
  56.     End Sub
  57.  
  58.     <DebuggerStepperBoundary>
  59.     Private Sub DrawBorder()
  60.  
  61.         Using g As Graphics = MyBase.CreateGraphics()
  62.             ControlPaint.DrawBorder(g, MyBase.ClientRectangle,
  63.                                     Me.BorderColor, 1, ButtonBorderStyle.Solid, ' left
  64.                                     Me.BorderColor, 1, ButtonBorderStyle.Solid, ' top
  65.                                     Me.BorderColor, 1, ButtonBorderStyle.Solid, ' right
  66.                                     Me.BorderColor, 1, ButtonBorderStyle.Solid) ' bottom
  67.  
  68.         End Using
  69.  
  70.     End Sub
  71.  
  72. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement