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

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

博客园 - 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;