【问题标题】:.net - Glass effect in C# 2.0 applications.net - C# 2.0 应用程序中的玻璃效果
【发布时间】:2009-06-14 17:21:23
【问题描述】:

如何在 .net 2.0 中的 Windows 窗体应用程序上赋予 Vista 或 Mac OS X 风格的玻璃效果?

【问题讨论】:

    标签: winforms .net-2.0 c#-2.0


    【解决方案1】:

    这是通过与 Vista DWM(桌面窗口管理器)API 互操作完成的。

    例如,导入这些函数:

    [DllImport("dwmapi.dll")]
    static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins);
    
    
    [StructLayout(LayoutKind.Sequential)]
    struct Margins
    {
        public int cxLeftWidth;
        public int cxRightWidth;
        public int cyTopHeight;
        public int cyBottomHeight;
    }
    

    然后您可以使用它从窗口顶部将玻璃“拉下”到客户区:

    GlassMargins.Top = 40;
    GlassMargins.Left = 0;
    GlassMargins.Right = 0;
    GlassMargins.Bottom = 0;
    
    DwmExtendFrameIntoClientArea(this.Handle, ref GlassMargins);
    

    从这里,您可以继续执行其他操作,例如在玻璃上绘制文本或图像,或在玻璃上放置控件,例如 Office 2007 样式的应用程序按钮。

    【讨论】:

      【解决方案2】:

      Vista Aero 中的玻璃窗边框是使用 DWM 合成的。这是操作系统级别的功能。如果您在 Vista 上运行您的应用程序,您应该免费获得玻璃边框。

      如果您想将玻璃效果扩展到客户区域,请使用DwmExtendFrameIntoClientArea,这是 Internet Explorer 在其工具栏中的操作方式。我怀疑你必须自己编写互操作来调用这个本机函数(或查看http://pinvoke.net)。

      【讨论】:

        【解决方案3】:

        【讨论】:

        • 这是一个不错的跨平台解决方案。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-01
        • 1970-01-01
        • 2014-05-02
        • 2018-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多