G
Guest
What's my best bet for adding a border or border property to a UserControl?
Thank You
Thank You
Bob Powell said:There are several ways to add a border to a control, these depend on the
type of border and more specifically the relationship between the border and
the client area.
The simplest way to add a border to a control is by overriding the
CreateParams property and adding the correct border style to the window
creation parameters. This is shown in detail in Windows Forms Tips and
Tricks.
The most comprehensive way to add a border is to override the WndProc of the
control and add message handlers for the WM_NCCREATE and WM_NCPAINT
messages. Using these you can add a border of any thickness and style you
choose because you have full control over the relationship between the
window and its client area and ful control over the drawing of the border
itself.
You should not simply use ControlPaint or any other graphics API methods to
just draw a border onto the client area of the control. Well, you can if you
wish but you can also re-paint a Rolls Roys using pebble-dash paint and a
paint roller. This isn't the correct way to do it however.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
Greg said:Thanks Bob and all. Yes, CreateParams does seem ideal. I found a sample on
Code Project and it worked fine. I was able to do 3D using ExStyle or flat
using Style.
By the way, is it possible to change the flat line from black to a gray
look.
Thank you!