user366312
user366312

Reputation: 17006

.net - Glass effect in C# 2.0 applications

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

Upvotes: 3

Views: 3395

Answers (3)

i_am_jorf
i_am_jorf

Reputation: 54640

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

Upvotes: 2

Factor Mystic
Factor Mystic

Reputation: 26790

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.

Upvotes: 4

MicTech
MicTech

Reputation: 45123

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

Upvotes: 1

Related Questions