110,825
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
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 button1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(button1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(pictureBox1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(textBox1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
}