Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
How to give shadow effect to WindowsForm button control


can able to get by custom button?
Posted
Comments
[no name] 27-Nov-15 9:41am    
Go through below link:
http://www.experts-exchange.com/questions/26161921/C-Form-Background-Drop-Shadow.html
Sathish km 27-Nov-15 9:48am    
this link require access..
DotNetSteve 27-Nov-15 19:44pm    
This is a link for winform - http://stackoverflow.com/questions/2463519/drop-shadow-in-winforms-controls
Sergey Alexandrovich Kryukov 27-Nov-15 19:52pm    
Makes sense, but see also my comment below. Would you post this link as a formal answer? It would make some reasonable answer/advice.
—SA
Sergey Alexandrovich Kryukov 27-Nov-15 19:49pm    
It looks like people feel tired of those slanted borders and windows shadows. Creating a custom shadow is not the simplest task. A very simple shadow can be rendered as a semi-transparent shape, but standard Windows shadow is a bit better: it also uses some blur, which is harder to render and can even compromise performace. And yet, good designers keep blaming developers of such shadows for their artificial and primitive look. So, why going int this struggle at all? Those shadows won't give you really pleasant or impressive look anyway... Just think about it.

[EDIT] And if you want to enable standard shadows, use the advice by DotNetSteve above.

—SA

1 solution

This solution helped me (Credit to Cody Gray, SO)


In WinForms, you can just override the form's protected CreateParams property and add the CS_DROPSHADOW flag to the class styles. For example:

C#
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 ...
}



1. 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.

2. 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.

3. 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. Theres 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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900