如何为WindowsForm按钮控件提供阴影效果?(WinForm).. [英] How to give shadow effect to WindowsForm button control?(WinForm)..

查看:997
本文介绍了如何为WindowsForm按钮控件提供阴影效果?(WinForm)..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How to give shadow effect to WindowsForm button control





可以通过自定义按钮获取?



can able to get by custom button?

推荐答案

这个解决方案对我有帮助(感谢科迪格雷,所以)





在WinForms中,您可以覆盖表单的受保护 CreateParams 属性,并将 CS_DROPSHADOW 标志添加到该类样式。例如:



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:

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.此标志仅适用于顶部级别的窗户。在Win32中,这意味着重叠和弹出窗口。它对子窗口(例如控件)没有影响。我以为我记得在某个地方听说过这个限制已经从Windows 8中删除了,但我找不到确认这个的链接,我没有安装Windows 8用于测试目的。



2.用户可能完全禁用了此功能。如果是这样,无论你如何要求它们,你都不会得到阴影。这是设计的。您的应用程序不应尝试覆盖此请求。您可以通过P /调用 SystemParametersInfo 函数并传递 SPI_GETDROPSHADOW 标志来确定是启用还是禁用投影。 br />


3. Aero主题还为顶级窗口添加了阴影。此效果与 CS_DROPSHADOW 分开且不同,仅在启用Aero时有效。没有办法关闭和打开单个窗口。此外,由于Aero主题已从Windows 8中删除,因此它不会有这些阴影。




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.


这篇关于如何为WindowsForm按钮控件提供阴影效果?(WinForm)..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆