.net - Move windows form from a picturebox in C# -


i have windows form without border. added picture box , want whole form moved when picture box clicked.

    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 header_image_mousedown(object sender, mouseeventargs e)     {         if (e.button == mousebuttons.left)         {             releasecapture();             sendmessage(handle, wm_nclbuttondown, ht_caption, 0);         }      } 

that code using atm.but problem if move cursor fast not sticked on picture box.

i tried find solution nothing came up. used info 2 links:

link 1

link 2

any ideas?

edit: here whole code of form

    public form1()     {         initializecomponent();     }      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 header_image_mousedown(object sender, mouseeventargs e)     {         if (e.button == mousebuttons.left)         {             releasecapture();             sendmessage(handle, wm_nclbuttondown, ht_caption, 0);         }      } 

refer code:

 private bool draging = false;          private point pointclicked;          private void picturebox1_mousemove(object sender, mouseeventargs e)          {              if (draging)              {                  point pointmoveto;                  pointmoveto = this.pointtoscreen(new point(e.x, e.y));                  pointmoveto.offset(-pointclicked.x, -pointclicked.y);                  this.location = pointmoveto;              }          }            private void picturebox1_mousedown(object sender, mouseeventargs e)          {              if (e.button == mousebuttons.left)              {                  draging = true;                  pointclicked = new point(e.x, e.y);              }              else              {                  draging = false;              }          }            private void picturebox1_mouseup(object sender, mouseeventargs e)          {              draging = false;          }


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -