Allows a common control to move the form with the left button.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.