In WinForms, you can just override the form's protected CreateParams
property and add the CS_DROPSHADOW
flag to the class styles. For example:
public class ShadowedForm : Form {
protected override CreateParams CreateParams {
get {
const int CS_DROPSHADOW = 0x20000;
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
// ... other code ...
}
But, a couple of caveats…
This flag works only on top-level windows. In Win32-speak, that means overlapped and popup windows. It has no effect on child windows (e.g. controls). I thought I remembered hearing somewhere that this limitation had been removed from Windows 8, but I can't find a link confirming this and I don't have Windows 8 installed for testing purposes.
It is possible that the user has disabled this feature altogether. If so, you won't get drop shadows, no matter how you ask for them. That's by design. Your application should not try and override this request. You can determine whether drop shadows are enabled or disabled by P/Invoking the SystemParametersInfo
function and passing the SPI_GETDROPSHADOW
flag.
The Aero theme also adds shadows to top-level windows. This effect is separate and distinct from CS_DROPSHADOW
, and works only when Aero is enabled. There's no way to turn it off and on for individual windows. Moreover, since the Aero theme has been removed from Windows 8, it won't ever have these shadows.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…