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

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

博客园 - 散步的蠕虫

[整理收藏]CSS Hack IE6,IE7,IE8 and Firefox 【转载】Javascript标准DOM Range操作 [收藏]SQL SERVER2005自动备份 [更新+源码]一个随时随地随便记的超轻量级的记事本软件WheneverNote V1.0.9.218 [发布+源码]一个随时随地随便记的超轻量级的记事本软件WheneverNote V1.0.9.215 [总结]Server Application Error(IIS5 HTTP500)内部错误分析及解决办法 [转载]XML和HTML常用转义字符 C# TO Excel 新概念III WCF - Message Security with Mutual Certificates WCF - Common Security Scenarios 【转载】LINQ to SQL (Part 5 - Binding UI using the ASP:LinqDataSource Control) 【转载】LINQ to SQL (Part 4 - Updating our Database) 【转载】LINQ to SQL (Part 3 - Querying our Database) 【转载】LINQ to SQL (Part 2 - Defining our Data Model Classes) 【转载】Using LINQ to SQL (Part 1) 常用开发辅助工具清单 JavaScript 实用方法库 Local Resource应用概述
[收藏]winform拖动方法
散步的蠕虫 · 2009-03-26 · via 博客园 - 散步的蠕虫

参考:http://topic.csdn.net/u/20080330/14/6b26bc14-0932-4016-9704-6f012ef04f66.html

方案1:通过重载消息处理实现。(优点:不用声明api函数。缺点是:窗体上放着Panel等容器就会失效) 

C# code

const int WM_NCHITTEST = 0x0084;
const int HTLEFT = 10;
const int HTCAPTION = 2;
const int HTCLIENT = 1;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCHITTEST:
if (m.Result == (IntPtr)HTCLIENT)
m.Result
= (IntPtr)HTCAPTION;
break;
}
}


方案2:发送一个拖动的消息(优点是:可以放在任意控件鼠标按下事件中) 

C# code

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 Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE
| HTCAPTION, 0);
}