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 } } |
|