你也可以这样做:
namespace abc
{
public abc:Form
{
private Button bn;
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;
[DllImportAttribute ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute ("user32.dll")]
public static extern bool ReleaseCapture();
...
\\为按钮bn添加鼠标事件
private void bn_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.bn.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}
}