C# WinForm Windows 7 Aero frosted glass effect

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

In Vista system, Microsoft provides Aero matte effect for the window procedure, as shown below. Then use C#

How to realize the matte effect.?


QQ图片20130901193319


Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.InteropServices;//The DLL statement references



namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        //The DLL statement
        [StructLayout(LayoutKind.Sequential)]
        public struct MARGINS
        {
            public int Left;
            public int Right;
            public int Top;
            public int Bottom;
        }

        //The DLL statement
        [DllImport("dwmapi.dll", PreserveSig = false)]
        static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS
        margins);

        //The DLL statement
        [DllImport("dwmapi.dll", PreserveSig = false)]
        static extern bool DwmIsCompositionEnabled();

        //Add the code directly
        protected override void OnLoad(EventArgs e)
        {
            if (DwmIsCompositionEnabled())
            {
                MARGINS margins = new MARGINS();
                margins.Right = margins.Left = margins.Top = margins.Bottom =
        this.Width + this.Height;
                DwmExtendFrameIntoClientArea(this.Handle, ref margins);
            }
            base.OnLoad(e);
        }

        //Add the code directly
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            if (DwmIsCompositionEnabled())
            {
                e.Graphics.Clear(Color.Black);
            }
        }

        public Form1()
        {
            InitializeComponent();
        }
    }
}



To achieve this effect is mainly the system call dwmapi.dll.

Dwmapi.dll Microsoft Desktop Window Manager API (public interface desktop window manager DWM) dynamic link library, the normal file, mainly used as a desktop effects API.


DWM is a new interface, in all Windows Vista version except Windows Vista Home of Basic provide DWM interface. So use this effect only in the Vista system.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Ted at December 08, 2013 - 12:04 PM