c# 实现Label拖动的两种方法
来源:互联网 发布:敏捷网络功能 编辑:程序博客网 时间:2024/06/05 09:07
原文:http://blog.csdn.net/lcawen88/article/details/7942801
在实现Label控件拖动,这里介绍两种有效地方法:
其一,通过调用api,通过消息来实现拖动(需要调用命名空间using System.Runtime.InteropServices;):
[DllImport("User32.DLL")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
[DllImport("User32.DLL")]
public static extern bool ReleaseCapture();
public const uint WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 61456;
public const int HTCAPTION = 2;
private void label1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(((Label)sender).Handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
}
其二,只是用MouseDown和MouseMove两个事件实现拖动:
private Point m_lastPoint;
private Point m_lastMPoint;
private void label1_MouseDown(object sender, MouseEventArgs e)
{
m_lastMPoint = Control.MousePosition;
m_lastPoint = (sender as Label).Location;
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
label1.Location = new Point(m_lastPoint.X + Control.MousePosition.X - m_lastMPoint.X, m_lastPoint.Y + Control.MousePosition.Y - m_lastMPoint.Y);
}
}
- c# 实现Label拖动的两种方法
- c# 实现Label拖动的两种方法
- 实现窗体拖动的两种方法
- C# 打印Label的两种方式及实现
- label自适应的两种方法
- 使用 C# 进行 label 打印 的两种方式
- 使用 C# 进行 label 打印 的两种方式 .
- 鼠标拖动层(可任意绑定DIV标签)的两种实现方法
- C#在运行后拖动控件的实现方法
- MFC:拖动无标题窗口的两种方法
- MFC两种拖动鼠标动态画图的方法
- C#实现Web文件上传的两种方法
- C#实现Web文件上传的两种方法
- C#实现Web文件上传的两种方法
- C#实现Web文件上传的两种方法
- C#实现SQLSERVER2000数据库备份还原的两种方法
- C# 两种实现编码转换的方法
- c# FTP的两种实现方法(一)-FtpWebRequest
- Codeforces Round #267 (Div. 2) C George and Job
- 使用LikedList 模拟一个堆栈或者俄队列数据结构。
- jbpm基础知识总结
- uvalive 2322(贪心)
- opencv2学习 ,读取图片,rgb2 lab
- c# 实现Label拖动的两种方法
- C++11新特性:类型别名,auto类型,decltype类型
- 让ArralList集合具备判重功能。去除重复元素
- android 打开amazon appstore
- 用Set集合,按照字符串的长度排序的方法
- 好的网站链接或文章链接(二)
- Map集合和TreeSet集合的使用:自定义比较器
- 瀑布式迭代与敏捷
- python 查看相关的help函数