c#窗体移动与窗体阴影效果
2015-12-31 11:24
645 查看
//步骤
//1.导入代码
//2.事件中添加form_1mousedown函数
//3.在load函数中定义AnimateWindow语句,注意有两个引用。
//4.DllImport若有错误,按shift+alt+F10添加第一个解决
[System.Runtime.InteropServices.DllImport("user32.dll")]//api加载声明
protected static extern bool AnimateWindow(IntPtr hWnd, int dwTime, int dwFlags);//定义AnimateWindow
public const Int32 AW_BLEND = 0x00080000;
public const Int32 AW_CENTER = 0x00000010;
public const Int32 AW_ACTIVATE = 0x00020000;
public const Int32 AW_HIDE = 0x00010000;
public const Int32 AW_SLIDE = 0x00040000;
public Form1()
{
InitializeComponent();
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);//API函数加载
,实现窗体边框阴影效果
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
}
#region 窗体拖动代码
//
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void Form1_MouseDown(object sender, MouseEventArgs e)//在窗体事件中手动添加,注意引用,无引用则无法完成
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
#endregion
#region 窗体边框阴影效果
const int CS_DropSHADOW = 0x20000;
const int GCL_STYLE = (-26);
//声明win32 api
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int deNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex); #endregion
private void Form1_Load(object sender, EventArgs e)
{
AnimateWindow(this.Handle, 500, AW_BLEND | AW_CENTER | AW_ACTIVATE);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
AnimateWindow(this.Handle, 500, AW_CENTER | AW_BLEND | AW_HIDE);
}
//1.导入代码
//2.事件中添加form_1mousedown函数
//3.在load函数中定义AnimateWindow语句,注意有两个引用。
//4.DllImport若有错误,按shift+alt+F10添加第一个解决
[System.Runtime.InteropServices.DllImport("user32.dll")]//api加载声明
protected static extern bool AnimateWindow(IntPtr hWnd, int dwTime, int dwFlags);//定义AnimateWindow
public const Int32 AW_BLEND = 0x00080000;
public const Int32 AW_CENTER = 0x00000010;
public const Int32 AW_ACTIVATE = 0x00020000;
public const Int32 AW_HIDE = 0x00010000;
public const Int32 AW_SLIDE = 0x00040000;
public Form1()
{
InitializeComponent();
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);//API函数加载
,实现窗体边框阴影效果
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
}
#region 窗体拖动代码
//
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void Form1_MouseDown(object sender, MouseEventArgs e)//在窗体事件中手动添加,注意引用,无引用则无法完成
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
#endregion
#region 窗体边框阴影效果
const int CS_DropSHADOW = 0x20000;
const int GCL_STYLE = (-26);
//声明win32 api
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int deNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex); #endregion
private void Form1_Load(object sender, EventArgs e)
{
AnimateWindow(this.Handle, 500, AW_BLEND | AW_CENTER | AW_ACTIVATE);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
AnimateWindow(this.Handle, 500, AW_CENTER | AW_BLEND | AW_HIDE);
}
相关文章推荐
- C#中字符串与字节数组互换的几种编码问题
- C#中as用法总结
- C#中using的用法
- 当前工作路径与应用程序启动路径
- C#双向链表简例
- 关于 C# 十进制不足补位的应用
- C#进行MapX二次开发之图层操作
- 天轰穿C#教程之数学运算符
- c# winform GMAP.NET离线模式怎么保存和使用离线地图?
- C#实现自动升级(附源码)
- 论C#如何实现多继承
- C#类型扩展方法—this参数修饰符
- 通过C#代码实现空间离散点的克里金(kriging)插值(一) 计算原理
- C#实现将程序运行信息写入日志的方法
- C# Directory类的操作
- 点滴积累【C#】---抓取页面中想要的数据
- GDI+坐标变换(C#)
- [原创]超强C#图片上传,加水印,自动生成缩略图源代码
- C#并行编程
- C#压缩文件夹