Public Class mytextbox
Inherits System.Windows.Forms.TextBox
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
setstyle(ControlStyles.UserPaint, True)
setstyle(ControlStyles.ResizeRedraw, True)
End Sub
Private _bordercolor As Color = Color.Red
<Description("边框颜色")> _
Public Property BorderColor() As Color
Get
Return _bordercolor
End Get
Set(ByVal Value As Color)
_bordercolor = Value
Me.Invalidate()
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
If Me.BorderStyle = BorderStyle.FixedSingle Then
DrawBackGround(e)
DrawMyString(e)
DrawBorderColor(e)
End If
End Sub
Private Sub DrawBackGround(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim c As Color = Me.BackColor
Dim g As Graphics = e.Graphics
Dim b As New SolidBrush(c)
g.FillRectangle(b, e.ClipRectangle)
End Sub
Private Sub DrawMyString(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim w As Single = (Me.Height - g.MeasureString(Me.Text, Me.Font).Height) / 2
g.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), 5, w)
End Sub
Private Sub DrawBorderColor(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics
g.DrawRectangle(New Pen(Me._bordercolor), New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
End Sub
End Class