HotDog's Blog

Hotdog (Robert Verpalen) about C# and vb.net

This blog hosted by:
http://blogs.vbcity.com      
  Home :: Syndication  :: Login

JunJuly 2008Aug
SMTWTFS
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

Articles

Archives

Topics

CONTACT

Fun but useful linkies

General

VS 2005

Wolfenstein ET

A usercontrol does not have a default borderstyle property. Still creating different sets of borders is very easy in the might .net.

Inside the System.Windows.Forms namespace (which is referenced by default in  a windowsapplication) there's a class named ControlPaint, which has some very interesting static (shared in vb.net) methods. One of those methods is the DrawBorder3D method, which does just that. You have the choice of several borders (defined in the Border3DStyle enumeration).

All you have to do is override the paint event of your custom control (or add a paint event catcher, but when overriding is possible, it's the preferred method) and do some drawing. For example:

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

ControlPaint.DrawBorder3D(

e.Graphics,ClientRectangle,Border3DStyle.Raised);

}

 

That's not too bad is it? The ControlPaint class has a lot of other very usefull methods. For example one paints a comboboxbutton. (all button drawing methods use the ButtonState enumaration so all states can be painted). Others a checkbox, a grid, a grabhandle, you name it. Even a way to draw a disabled image windows style.

Have fun exploring :D

posted on Thursday, September 09, 2004 7:53 AM