109,341
社区成员




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);
}
}
}