0

I want to be able to move with the mouse a form without border and title bar in c#.

I looked over youtube but i can't find anything that is working.

Someone can help me?

Detroit
  • 11
  • 5
  • "Dragable a non sizeable form" - that's a contradiction. You can't have a window with a draggable resize handle that is "non-sizable". Please clarify what you're trying to accomplish. – Dai Jul 04 '20 at 14:00
  • My form border style is None! So now im trying to make the form dragable with mouse so i can drag the form and change the location of the form! – Detroit Jul 04 '20 at 14:04
  • Welcome to StackOverflow. Thank you for taking the time to share your problem. What you asking for is unclear. What is your goal and your difficulty? What have you done so far? Please try to better explain your issue, your dev env & data structures, as well as to share more code (no screenshot), images or sketches of the screen, and user stories or scenario diagrams. To help you improve your requests, please read the *[How do I ask a good question](https://stackoverflow.com/help/how-to-ask)* & [Writing the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question). –  Jul 04 '20 at 14:07
  • What do you mean by "*dragable*": can you explain and provide an example of usage, please? –  Jul 04 '20 at 14:07
  • You know when u make a project and make your formBorderStyle to None so its just a window that doesnt move u cannot move it so im trying to make the form able to move with my mouse so i can drag and move the form. example i want to make the form dragable that i can drag it with my mouse and move it from a display to my other display!. – Detroit Jul 04 '20 at 14:10
  • Ok, can you add that to the question, please? –  Jul 04 '20 at 14:12
  • Yes but i found a video thank god.Thanks so much for trying to help me guys.Should i delete the question or what now? – Detroit Jul 04 '20 at 14:16
  • Look [here](https://stackoverflow.com/questions/1592876/make-a-borderless-form-movable) – TaW Jul 04 '20 at 14:27

1 Answers1

0

You can use the form's MouseDown, Up and Move events with a conditional variable like that:

private bool IsMoving;
private Point LastCursorPosition;

private void FormTest_MouseDown(object sender, MouseEventArgs e)
{
  IsMoving = true;
  LastCursorPosition = Cursor.Position;
}

private void FormTest_MouseUp(object sender, MouseEventArgs e)
{
  IsMoving = false;
}

private void FormTest_MouseMove(object sender, MouseEventArgs e)
{
  if ( IsMoving )
  {
    int x = Left - ( LastCursorPosition.X - Cursor.Position.X );
    int y = Top - ( LastCursorPosition.Y - Cursor.Position.Y );
    Location = new Point(x, y);
    LastCursorPosition = Cursor.Position;
  }
}

It works with the background of the form but you can add this to any other control too.