.net-C#2.0应用程序中的玻璃效果 [英] .net - Glass effect in C# 2.0 applications

查看:51
本文介绍了.net-C#2.0应用程序中的玻璃效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I give a Vista or Mac OS X style glass effects on windows forms applications in .net 2.0?

推荐答案

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

This is done using interop with the Vista DWM (Desktop Window Manager) 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;
}

然后,您可以使用它从玻璃杯的顶部下拉玻璃杯窗口向下进入客户区域:

Then you can use this to "pull down" glass from the top of the window down into the client area:

GlassMargins.Top = 40;
GlassMargins.Left = 0;
GlassMargins.Right = 0;
GlassMargins.Bottom = 0;

DwmExtendFrameIntoClientArea(this.Handle, ref GlassMargins);

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

From here, you can go on and do other things, like draw text or images onto the glass, or put controls on it, such as a Office 2007 style application button.

这篇关于.net-C#2.0应用程序中的玻璃效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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