c# - How to move a borderless form only vertically? -


i have created winform application school project. in situation want let user move form vertically dragging form.

so, have tried this.

 private bool dragging = false;  private point pointclicked;   private void form1_mousemove(object sender, mouseeventargs e)  {      if (dragging)      {          point pointmoveto;          pointmoveto = this.pointtoscreen(new point(e.y,e.y));          pointmoveto.offset(-pointclicked.x, -pointclicked.y);          this.location = pointmoveto;      }  }   private void form1_mousedown(object sender, mouseeventargs e)  {      dragging = true;      pointclicked = new point(e.x, e.y);  }  private void form1_mousedown(object sender, mouseeventargs e)  {      dragging = false;  } 

but doesn't seem work. moves form across screen. so, there way restrict form movement vertical?

try this:

public partial class form1 : form {     private bool dragging = false;     private int pointclickedy;      public form1() {         initializecomponent();     }      private void form1_mousedown(object sender, mouseeventargs e) {         dragging = true;         pointclickedy = e.y;     }      private void form1_mouseup(object sender, mouseeventargs e) {         dragging = false;     }      private void form1_mousemove(object sender, mouseeventargs e) {         if (dragging) {             int pointmovetoy = e.y;             int delta = pointmovetoy - pointclickedy;             location = new point(location.x, location.y + delta);         }     } } 

Comments