0

I am devoloping app in Visual Studio using C#. I set no border in my form and I want to make my form dragable.

enter image description here

I need to get position of mouse according to form to get my code work

enter image description here

This is my code to make it dragable

private void timer1_Tick(object sender, EventArgs e)
{
    //HERE CODE SET POSITION OF MY FORM
    this.Location = new Point(MousePosition.X - MOUSE POSITION ACCORDING TO FORM, MousePosition.Y - MOUSE POSITION ACCORDING TO FORM);
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    timer1.Enabled = true;
}

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
    timer1.Enabled = false;
}

Your answers will be appreciated.

coderblogger
  • 84
  • 11
Dominikis
  • 52
  • 1
  • 1
  • 9
  • I don't quite get what you're asking, but I think you're looking for one or the other of `Control.PointToClient` or `Control.PointToScreen`. – adv12 Mar 14 '16 at 18:06
  • Or look at the ClientRectangle property of the form: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.clientrectangle%28v=vs.110%29.aspx – ManoDestra Mar 14 '16 at 18:06
  • Possible duplicate of [Winforms - Click/drag anywhere in the form to move it as if clicked in the form caption](http://stackoverflow.com/questions/30184/winforms-click-drag-anywhere-in-the-form-to-move-it-as-if-clicked-in-the-form) – NineBerry Mar 14 '16 at 18:11
  • Another possible duplicate with a similar solution: http://stackoverflow.com/questions/1592876/make-a-borderless-form-movable?lq=1 – NineBerry Mar 14 '16 at 18:14

1 Answers1

2

Use the PointToClient() method of the form.

NineBerry
  • 26,306
  • 3
  • 62
  • 93