XP-Style border for PictureBox

M

Marco

Hi to All,

Is it possibile to use an XP-Style border for a picturebox? I am referring
to the border that, under XP, listboxes and textboxes have (i.e. a single
blue line, if you use the default theme).

I have tried many ways, with no luck!

Can you please help?
Thanks.

Marco
 
K

Ken Tucker [MVP]

Hi,

You have override the wm_ncpaint message to change the border of a
control. I wrote a class that uses native windows to change the border
of a control. Make sure the control has to have its borderstyle set to
anything other than none.


Public Class XpBorderChanger
Inherits NativeWindow

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 Integer

Private ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)
Me.ctrl = ctrl
End Sub


Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages

Const WM_NCPAINT As Integer = &H85

If m.Msg = WM_NCPAINT Then
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)

Dim pXp As Pen = New Pen(Color.Blue, 3)

g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1, ctrl.Height - 1)
ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If
End Sub

Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class

http://www.onteorasoftware.com/downloads/borderchanger.zip


Ken
-----------------------
 

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