Adding a drop shadow to a windows form
February 13th, 2007 by Chris
This nice tip allows the addition of a drop shadow to any form you want. The drop shadow is a nice effect that comes standard with Windows XP and Vista. It just gives the form a little mode depth and a nicer more modern look.

As you can see above, the difference is slight, but in the right hand image you can see a drop shadow around the form.
To implement this feature, you need to add in the following code to your forms.
C#:
using System; using System.Windows.Forms; using System.Security; using System.Security.Permissions; namespace System.Windows.Forms { public class DropShadowForm : Form { private const int CS_DROPSHADOW = 0x00020000; public DropShadowForm() { } protected override CreateParams CreateParams { [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] get { CreateParams parameters = base.CreateParams; if (DropShadowSupported) { parameters.ClassStyle = (parameters.ClassStyle | CS_DROPSHADOW); } return parameters; } } public static bool DropShadowSupported { get { return IsWindowsXPOrAbove; } } public static bool IsWindowsXPOrAbove { get { OperatingSystem system = Environment.OSVersion; bool runningNT = system.Platform == PlatformID.Win32NT; } } } }
Posted in Windows Forms |
June 25th, 2008 at 9:41 am
it works but i dont have a clue how…
Could you just say how it would be possible to make the shadow a bit bigger?
Thank u,
Sam