窗体移动和窗体阴影代码
1 public partial class Form2 : Form 2 { 3 //窗体阴影 4 private const int CS_DropSHADOW = 0x20000; 5 private const int GCL_STYLE = (-26); 6 [DllImport("user32.dll", CharSet = CharSet.Auto)] 7 public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong); 8 [DllImport("user32.dll", CharSet = CharSet.Auto)] 9 public static extern int GetClassLong(IntPtr hwnd, int nIndex); 10 11 public Form2() 12 { 13 InitializeComponent(); 14 SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);//调用窗体阴影函数 15 } 16 17 #region//窗体移动API 18 [DllImport("user32.dll")] 19 public static extern bool ReleaseCapture(); 20 [DllImport("user32.dll")] 21 public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam); 22 public const int WM_SYSCOMMAND = 0x0112; 23 public const int SC_MOVE = 0xF010; 24 public const int HTCAPTION = 0x0002; 25 [DllImport("user32")] 26 private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam); 27 private const int WM_SETREDRAW = 0xB; 28 29 private void Form2_MouseDown(object sender, MouseEventArgs e)//一个鼠标按下事件 30 { 31 if (this.WindowState == FormWindowState.Normal) 32 { 33 ReleaseCapture(); 34 SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); 35 } 36 } 37 #endregion