Painting a textbox Border--the Answer

T

Tal McMahon

After spending a morning wading through all the the Wrong answers and
responses I have figured out how to change the border on a textbox.

Here is the code:

Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
hwnd As Integer, ByVal hdc As Integer) As Integer
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Const WM_PAINTBKG As Integer = 15
If m.Msg = WM_PAINTBKG Then
Dim g As Graphics = Me.CreateGraphics
Dim mypen As Pen = New
Pen(System.Drawing.SystemColors.GrayText, 1)
Dim width As Integer = Bounds.Width - 1
Dim height As Integer = Bounds.Height - 1
g.DrawRectangle(mypen, 0, 0, width, height)
mypen.Dispose()
g.Dispose()
End If
End Sub





I hope it saves some of you some trouble

Tal McMahon
 
S

Steve S

While your approach probably will work....... accept the fact that your
also relaying on the call to the winAPI to also work... through unmanaged
code.......

Have you looked at inheriting the textbox (to define one of your own)...
and override the paint function ? I'm not even sure this would work on the
border...... but it might be there...... as the border is a property that
is set.... and must be painted .......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top