分享

C#程序实现aero特效的方法

 缘木求鱼001 2012-10-05
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1 ( )
        {
            InitializeComponent();
        }
        #region 窗体特效
        #region Aero玻璃特效
        [DllImport("dwmapi.dll" , PreserveSig = false)]
        static extern void DwmExtendFrameIntoClientArea ( IntPtr hwnd , ref Margins margins );
        [DllImport("dwmapi.dll" , PreserveSig = false)]
        static extern bool DwmIsCompositionEnabled ( );
        [StructLayout(LayoutKind.Sequential)]
        class Margins
        {
            public int Left , Right , Top , Bottom;
        }
        #endregion
 
 
        #region 窗体移动
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture ( );
        [DllImport("user32.dll")]
        public static extern bool SendMessage ( IntPtr hwnd , int wMsg , int wParam , int lParam );
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;
        #endregion
 
 
        #region 重绘窗体
        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);
        }
        protected override void OnPaintBackground ( PaintEventArgs e )
        {
            base.OnPaintBackground(e);
            if (DwmIsCompositionEnabled())
            {
                e.Graphics.Clear(Color.Black);
            }
        }
        #endregion
        #endregion
 
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约