C#窗体无边框窗体边框阴影

 1 //引入命名空间
 2 using System.Runtime.InteropServices;
 3 
 4 private const int CS_DropSHADOW = 0x20000;
 5 private const int GCL_STYLE = (-26);
 6 //导入user32
 7 [DllImport("user32.dll", CharSet = CharSet.Auto)]
 8 
 9 [DllImport("user32.dll", CharSet = CharSet.Auto)]
10 
11 public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
12 public static extern int GetClassLong(IntPtr hwnd, int nIndex);
13 //窗体阴影方法
14 private void SetShadow()
15 {
16   SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW); 
17 }

通过以上代码在构造函数中调用方法 SetShadow(),在事件代码中直接调用。

即可实现无边框窗体的阴影效果了

欢迎参考!

posted @ 2014-05-19 17:11  林晓东  阅读(699)  评论(1)    收藏  举报