+ Reply to Thread
Results 1 to 2 of 2

Thread: How to move a form on mouse click

  1. #1

    How to move a form on mouse click

    I am creating my own winform style , so i had to remove the borders of the form and put my style as a background , the issue i am having now is that i can`t move the form when i want to , i tried the mouse down event but i do not know what kind of values should i type .

  2. #2
    First of all , include that library :
    Code:
    using System.Runtime.InteropServices;
    Then :
    Code:
            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();
    Finally inside Mouse_Down Event :
    Code:
                if (e.Button == MouseButtons.Left)
                {
                    ReleaseCapture();
                    SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
                }
    This will move the form whenever user click on form and move mouse while holding the click , it is exactly like the normal form moving .

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts