|3||Code Libraries|| |
Setting a UserControl's BorderStyle
Provide unique border style options by modifying the WindowStyle directly with this drop-in code
Download the BorderStyle control code (5kb)This article provides you with drop-in code to supply Appearance and BorderStyle properties to any UserControl (or, in fact, any other object with a window handle) so you can set flat or 3D borders and you can choose no border, thin, 3D raised or 3D sunken border styles.
VB creates a border on a UserControl through an extended Window Style provided in Win32,
WS_EX_CLIENTEDGE. You can see this by using the SPY++ program provided with various Microsoft
Development products (on the VB Enterprise CD it can be found in the Tools directory). Start
SPY++ and use the Window Finder tool to point at a VB User Control with BorderStyle set
to 1. You will see WS_EX_CLIENTEDGE in the list of WindowStyles for that window.
When this style is set, Windows automatically draws a border around the window and
resets the client region of the window to leave out the border.
You can set other styles for a controls border by using the API SetWindowLong function. The extended style WS_EX_STATICEDGE provides a thin, sunken border whilst the extended style WS_EX_WINDOWEDGE in combination with the standard styles WS_BORDER and WS_THICKFRAME provides a raised edge.
The code in the control in the download provides you all you need to add these styles to your own user control. It's easy! And you don't have to change any of your resizing code or drawing code to add it, because VB's ScaleWidth and ScaleHeight properties use the underlying GetClientRect API and hence take account of the differing border styles.
Back to top
Back to Source Code Overview