これは(私はボーダレスなフォームを持っているとき)私が使用する標準コードです:
using System.Runtime.InteropServices;
..
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 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();
private void YourLabel_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
私はそれがフォームのキャプションバーをヒットした偽物だと思います。
もちろん、同じコードにフォームを含め、任意の数の他のコントロールのMouseDown
イベントをフックできます。
出典
2017-04-09 07:12:08
TaW
[This(http://stackoverflow.com/a/11043661/815938)は、最初のアプローチの例です。 – kennyzx