最简单的重绘之TextBox边框(vb.net)

 已经简单的无可救药,还是直接上代码吧:

Imports System.Drawing Imports System.Windows.Forms Public Class TextBox Inherits Windows.Forms.TextBox Private Declare Function GetWindowDC Lib "user32.dll" (ByVal hwnd As Integer) As Integer Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer Private Const WM_NCPAINT As Integer = &H85 Private Const WM_PAINT As Integer = &HF& Sub New() MyBase.BorderStyle = Windows.Forms.BorderStyle.FixedSingle End Sub Protected Overloads Overrides Sub WndProc(ByRef m As Message) MyBase.WndProc(m) Select Case m.Msg Case WM_NCPAINT, WM_PAINT Dim hDC As Integer Dim pen As New Pen(BorderColor) hDC = GetWindowDC(m.HWnd) Dim g As Graphics = Graphics.FromHdc(hDC) g.DrawRectangle(pen, 0, 0, Me.Width - 1, Me.Height - 1) ReleaseDC(m.HWnd, hDC) g.Dispose() pen.Dispose() End Select End Sub Private m_BorderColor As Color = Color.Black Public Property BorderColor() As Color Get Return m_BorderColor End Get Set(ByVal value As Color) m_BorderColor = value Me.Refresh() End Set End Property End Class

你可能感兴趣的:(.net)