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

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
J
Java Code Geeks
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
量子位
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
爱范儿
爱范儿

博客园 - 散步的蠕虫

[整理收藏]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);
}