C#鼠标拖动任意控件(winform)
分类: c#2011-08-15 22:51 178人阅读 评论(0) 收藏 举报
1 using System.Runtime.InteropServices; 2 //并为控件 添加 MouseDown 事件 3 4 // C#鼠标拖动任意控件 5 6 // 利用Windows的API函数:SendMessage 和 ReleaseCapture 7 const uint WM_SYSCOMMAND = 0x0112; 8 const uint SC_MOVE = 0xF010; 9 const uint HTCAPTION = 0x0002; 10 11 [DllImport("user32.dll", EntryPoint = "SendMessageA")] 12 private static extern int SendMessage(IntPtr hwnd, uint wMsg, uint wParam, uint lParam); 13 [DllImport("user32.dll")] 14 private static extern int ReleaseCapture(); 15 16 void ControlMouseDown(object sender, MouseEventArgs e) 17 { 18 ReleaseCapture(); 19 SendMessage((sender as Control).Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); 20 }
[转]C#鼠标拖动任意控件
时间: 2024-10-12 19:24:44