.net - Glass effect in C# 2.0 applications

时光总嘲笑我的痴心妄想 提交于 2019-12-06 09:25:13

问题


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


回答1:


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.




回答2:


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




回答3:


DevExpress components

  • for .NET 2.0

http://devexpress.com/Products/NET/DXperience/editionWinForms.xml


Creating a Glass Button using GDI+

http://www.codeproject.com/KB/buttons/glassbutton.aspx



来源:https://stackoverflow.com/questions/993249/net-glass-effect-in-c-sharp-2-0-applications

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