Point mouseOff; // the variable that moves the cursor.
Bool leftFlag; // whether the label is left
Private void form=mousedown (object sender, MouseEventArgs e)
{
If (e. Button = MouseButtons. Left)
{
MouseOff = new Point (-e. X,-e. Y); // obtain the variable value.
LeftFlag = true; // click the left button to press the time mark to set it to true;
}
}
Private void form=mousemove (object sender, MouseEventArgs e)
{
If (leftFlag)
{
Point mouseSet = Control. MousePosition;
MouseSet. Offset (mouseOff. X, mouseOff. Y); // you can specify the position after moving.
Location = mouseSet;
}
}
Private void form=mouseup (object sender, MouseEventArgs e)
{
If (leftFlag)
{
LeftFlag = false; // mark it as false after the mouse is released;
}
}
Method 2
[DllImport ("user32.dll")] // ************************ drag a widget without a form
Public static extern bool ReleaseCapture ();
[DllImport ("user32.dll")]
Public static extern bool SendMessage (IntPtr hwnd, int wMsg, int wParam, int lParam );
Public const int WM_SYSCOMMAND = 0x0112;
Public const int SC _MOVE = 0xF010;
Public const int HTCAPTION = 0x0002;
Next, you need to drag the triggered control to write this sentence.
Private void gPanelTitleBack_MouseDown (object sender, MouseEventArgs e)
{
ReleaseCapture ();
SendMessage (this. handle, WM_SYSCOMMAND, SC _MOVE + HTCAPTION, 0); // ********************** call the function of the mobile formless control.
}