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

 

This is only a very small addition to
http://blogs.vbcity.com/hotdog/archive/2004/09/09/272.aspx , but I figured this is something that will come in handy often enough to put in a seperate post:

You want your control to behave as if a button is clicked? All you have to do is have a raised 3d border in normal circumstances and set it to sunken while the mouse is down (restoring it afterwards) eg:

 

private Border3DStyle borderstyle = Border3DStyle.Raised;

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

ControlPaint.DrawBorder3D(

e.Graphics,ClientRectangle,borderstyle);

}

protected override void OnMouseDown(MouseEventArgs e)

{

borderstyle=Border3DStyle.Sunken;

Invalidate();

base.OnMouseDown (e);

}

protected override void OnMouseUp(MouseEventArgs e)

{

borderstyle=Border3DStyle.Raised;

Invalidate();

base.OnMouseUp (e);

}

posted on Thursday, September 09, 2004 8:18 AM