views:

301

answers:

2

is there a way to add a drop shadow to controls?

are there any controls out there with this feature?

+1  A: 

There is in WPF if you can stretch to using that instead, I don't believe there is an alternative in Windows Forms due to the limited capabilities of GDI+.

This article might be of interest if you're after something simple (and for rectangular controls!)

Andy Shellam
he could probably do it if he wrote custom controls and added a shadow effect in an overridden Paint method.
FrustratedWithFormsDesigner
@Andy Shellam: thanks at least panels will look nicer now...
Luiscencio
@FrustratedWithFormsDesigner - yeah, that's what that article in my post is doing. It's still a horrible, horrible way to do a relatively simple thing!
Andy Shellam
+6  A: 

You have to overwrite the CreateParamsproperty like this:

private const int CS_DROPSHADOW = 0x00020000;
protected override CreateParams CreateParams
{
    get
    {
        // add the drop shadow flag for automatically drawing
        // a drop shadow around the form
        CreateParams cp = base.CreateParams;
        cp.ClassStyle |= CS_DROPSHADOW;
        return cp;
    }
}
Simon Linder
Awesome! Is there a complete list of other neat tricks like this?
FrustratedWithFormsDesigner
@FrustratedWithFormsDesigner: LOL - I love your nick
Luiscencio
@FrustratedWithFormsDesigner: What kind of tricks do you think about?
Simon Linder
@Simon Linder: this works great for Forms.. any ideas on applying this to controls?
Luiscencio
@Luiscencio: I'm not sure but as this property applies to a lot of standard controls (as e.g. Button), the CS_DROPSHADOW flag may also apply to them. Check the MSDN for classes that implement the CreateParams property.
Simon Linder
@FrustratedWithFormsDesigner: CS_DROPSHADOW is a class style. There are also others, see http://msdn.microsoft.com/en-us/library/ms633574(VS.85).aspx and WinUser.h from you SDK installation path.
Simon Linder