惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

博客园 - lisugar

BPEL元素定义层次关系 去黑头的方法.... BPEL中的XML元素解析 2 - lisugar - 博客园 BPEL中的XML元素解析 WDSL文件中的XML元素 WS-BPEL2.0 Specification 什么是BPEL - 老外们给的定义 你们猜吧:) 劳动人民的智慧是无穷的,只要你有发现的眼睛 安全 C# .net 2005 beta 所有安装连接 今天最大的收获 C#程序分类管理 C#创建目录的方法 数据库中权限分配技巧 [wenService]ASP.Net+XML打造留言薄 [webService]如何编写需要授权才能使用的WebService?(原著网事如风) [[Advanced T-SQL]] Automate the Generation of Stored Procedures for Your Database [C#]Windows服务程序[转载西门吹雪的好文章]
.net中实现拖拽控件
lisugar · 2005-06-22 · via 博客园 - lisugar

在.net中实现拖拽控件主要用到以下函数:
MouseDown(object sender, MouseEventArgs e)
MouseUp(object sender, MouseEventArgs e)
MouseMove(object sender, MouseEventArgs e)

这三个函数的作用分别是鼠标按下时激活,鼠标松开激活和鼠标移动
需要考虑的情况如下
1. 只有在鼠标按下的时候才可以使用鼠标移动事件
2. 鼠标移动的时候控件重新调整位置

为了有效控制第一个条件,所以可以将鼠标移动事件的绑定推迟到鼠标按下事件中,而不是在初始化时完成,另外要记录下初始状态下鼠标位于控件中的坐标,这里注意MouseEventArgs参数中的X,Y表示的是鼠标在当前控件中的layout坐标,而不是鼠标在主窗口中的坐标。
rivate void button1_MouseDown(object sender, MouseEventArgs e)
        {
            this.tmpx = e.X;
            this.tmpy = e.Y;
            this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
        }
同时在鼠标送开事件中再将该方法绑定脱离
        private void button1_MouseUp(object sender, MouseEventArgs e)
        {
            this.button1.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
        }
最后是MouseMove事件
        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            this.button1.Location = new System.Drawing.Point(this.button1.Location.X + e.X - this.tmpx, this.button1.Location.Y + e.Y - this.tmpy);
        }
这里重新计算了控件的新位置。
例子中使用了button作为实验对象并且额外定义了
        private int tmpx = 0;
        private int tmpy = 0;