下面是画xp风格的textbox,一样的道理 Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As IntPtr) As IntPtr Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr Protected Overrides Sub wndproc(ByRef m As Message) MyBase.WndProc(m) Dim i As IntPtr If m.Msg = 15 Or m.Msg = 307 Then i = GetWindowDC(TextBox1.Handle) If i.ToInt32 = 0 Then Return Else Dim g As Graphics = Graphics.FromHdc(i) g.DrawRectangle(Pens.Red, 0, 0, TextBox1.Width - 1, TextBox1.Height-1) g.Dispose() End If m.Result = IntPtr.Zero ReleaseDC(m.HWnd, i) End If End Sub
Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As IntPtr) As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr
Protected Overrides Sub wndproc(ByRef m As Message)
MyBase.WndProc(m)
Dim i As IntPtr
If m.Msg = 15 Or m.Msg = 307 Then
i = GetWindowDC(TextBox1.Handle)
If i.ToInt32 = 0 Then
Return
Else
Dim g As Graphics = Graphics.FromHdc(i)
g.DrawRectangle(Pens.Red, 0, 0, TextBox1.Width - 1, TextBox1.Height-1)
g.Dispose()
End If
m.Result = IntPtr.Zero
ReleaseDC(m.HWnd, i)
End If
End Sub
protected override void WndProc(ref Message m)
{
base.WndProc (ref m); //这里设个断点看看具体消息然后就可以在这前面放if去执行你自己的代码
}