Allows a common control to move the form with the left button.
The Code is as follows:
/// <Summary> set the control that allows the form to be moved with the left mouse button. /// </summary> /// <param name = "form"> the form to be moved, generally, FormBorderStyle = FormBorderStyle is set. none Form </param> /// <param name = "control"> controls that can be left-clicked to move the form </param> public static void SetMoveFormControl (Form form, Control control) {control. mouseDown + = (s, e) =>{ ReleaseCapture (); SendMessageA (int) form. handle, 0xa1, 2, 0) ;};} [DllImport ("user32.dll")] private static extern int ReleaseCapture (); [DllImport ("user32.dll")] private static extern int SendMessageA (int hwnd, int wMsg, int wParam, int lParam );
In vbprogramming, click the left button on the control label1 to move the entire form. How to write the code?
Add a label Control
'Form code
Private downx As Long
Private downy As Long
Private xx As Long
Private yy As Long
Private MouseDown As Boolean
Private Sub labeldomainmousedown (Button As Integer, Shift As Integer, X As Single, Y As Single)
Downx = X
Downy = Y
MouseDown = True
End Sub
Private Sub labelease mousemove (Button As Integer, Shift As Integer, X As Single, Y As Single)
Xx = X
Yy = Y
If MouseDown = True Then Me. Move Me. Left + (xx-downx), Me. Top + (yy-downy)
End Sub
Private Sub labeldomainmouseup (Button As Integer, Shift As Integer, X As Single, Y As Single)
MouseDown = False
End Sub
That's all !!
How does vc ++ respond to mouse events outside the window? (Including moving the mouse, clicking the left button, and so on)
This requires a mouse hook...
If you want to take screenshots, you can create a transparent form to cover the whole screen.