.net - Glass effect in C# 2.0 applications

不打扰是莪最后的温柔 提交于 2019-12-04 15:47:47

This is done using interop with the Vista DWM (Desktop Window Manager) API.

For example, import these functions:

[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);

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.

i_am_jorf

The glass window borders in Vista Aero are composited using the DWM. This is an OS-level feature. If you run your app on Vista, you should get the glass border for free.

If you want to extend the glass effect into the client area, use DwmExtendFrameIntoClientArea, which is how Internet Explorer does it in its toolbar. I suspect you'll have to write the interop to call this native function yourself (or check http://pinvoke.net).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!