日期:2014-05-17 浏览次数:20826 次
using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("user32.dll")] static extern bool ReleaseCapture(); [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam); private readonly UInt32 WM_SYSCOMMAND = 0x112; private readonly UInt32 SC_MOVE = 0xF010; private readonly UInt32 HTCAPTION = 2; private void Form1_Load(object sender, EventArgs e) { this.MouseDown += MyMouseMove; foreach (Control c in this.Controls) { c.MouseDown += MyMouseMove; } } private void MyMouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } } } }
------解决方案--------------------
没必要所有控件都可以拖动窗体吧
------解决方案--------------------