Groups | Blog | Home
all groups > dotnet windows forms controls > february 2008 >

dotnet windows forms controls : .NET 2.0 border around controls



Jarod80
2/25/2008 6:56:01 PM
How is it possibile to draw a black border around the controls (TextBox,
Combobox) while they're focused, not in designtime, at runtime?

I have inherited the controls in some customclasses of mine.

The problem I seem to have is that my border get overwritten almost always.

Thanks.
Michael C
2/26/2008 2:57:24 PM
[quoted text, click to view]

This won't work the way you're trying to do it. If you draw 1 pixel wider
than your textbox then it won't be visible because it will be outside the
bounds of the control. If you draw inside the bounds then the drawing of the
control will overwrite it. The second option would look pretty ordinary even
if it was possible.

What I would do is create a seperate control or class that acts as the
border. For the control you could position the control behind the
appropriate control and size it to be 2 pixels wider and taller. If you use
a class you could simply draw to the form using Graphics.DrawRect. The
advantage to either of these methods is that you don't have to modify every
control on your form, this will work with pretty much all controls. You
could trap events of the form to check when focus has changed.

Michael

Michael C
2/26/2008 3:00:17 PM
[quoted text, click to view]

I forgot to ask, why do you want to do this? It's non standard windows
behaviour and won't look all the good. The only reason I would do this is if
you have users with a disability of some sort that makes this a requirement.
But even then aren't there features built into windows for these users?
[quoted text, click to view]

Bob Powell [MVP]
2/27/2008 12:00:00 AM
It's tricky to do but the correct way is to change the size of the non
client area and draw in that.

--
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.





[quoted text, click to view]
Jarod80
2/27/2008 9:45:39 AM
Thank you very much, I thought it could look good, something different from
the always used background color change.
Isn't there a property, an event or a function to override to achieve it
without enboxing the control in a bigger control?
Something like the PaintAdornments for design.

If I'll need to follow your method I will surely also follow your
suggestions :) and I'll just forget about it cause I don't want to lose or
forward all the properties and events...

thanks you



"Michael C" <mike@nospam.com> ha scritto nel messaggio
news:u%23ReXwCeIHA.4260@TK2MSFTNGP05.phx.gbl...
[quoted text, click to view]
Michael C
2/29/2008 10:14:45 AM
[quoted text, click to view]

Fair enough. I'm not a big fan of the idea but it wouldn't be too bad.

[quoted text, click to view]

See my other post.

Michael

AddThis Social Bookmark Button