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);
}