0

Possible Duplicate:
C# - Make a borderless form movable?
Drag borderless windows form by mouse

Ok, I have made a form with a control in it. The form is borderless. The control inside the form is called navigationPanel1. I want to be able to click and drag on the control to move the form. How do i do that?

Community
  • 1
  • 1
Hunter Mitchell
  • 7,063
  • 18
  • 69
  • 116
  • Loads of sources on the net for this with working examples: http://www.codeproject.com/Articles/13571/Draggable-Form-Drag-a-Borderless-Form-by-Clicking – Adam Houldsworth May 22 '12 at 12:51
  • @CodeCaster i can assure you that this is my first post on this subject. – Hunter Mitchell May 22 '12 at 12:52
  • @AdamHouldsworth This is not a duplicate – Hunter Mitchell May 22 '12 at 12:53
  • 1
    @EliteGamer The duplicate is a question asked by someone else. When you make a question in SO the site does a search for you to help you avoid making another of the same. Duplicates are not usually from the same person in this context. – Adam Houldsworth May 22 '12 at 12:53
  • @AdamHouldsworth Oh... i am so sorry – Hunter Mitchell May 22 '12 at 12:55
  • No problem, the duplicates have the added benefit of answering your question (usually), even though it can feel little "harsh" to get your question closed off. Hopefully you will find your answer. – Adam Houldsworth May 22 '12 at 12:56
  • @EliteGamer, not a problem, you have to learn somehow. Typically when people post "duplicate of" it also means that the links they gave you contain the answer to the question you asked. (true, in this case) – Chris Pfohl May 22 '12 at 12:56

1 Answers1

-1

You have to subscribe for the mouse-down, mouse-up and mouse-move events. In the mouse-move you set the location of your form to the new location (this u have to calculate). the code in mouse-move only should be executet if the mouse-button is down (save this state)

Tomtom
  • 9,087
  • 7
  • 52
  • 95
  • While this may appear to work somewhat in some cases, it breaks down in others, e.g. if you drag the form upwards from the topmost pixel – you won't get a MouseMove event, thus no movement happens. Same can happen if you move the mouse fast enough that the pointer is outside the form for a moment. It's much better to just let the window manager do its thing [by telling him »Hey, someone started dragging on the title bar«](http://stackoverflow.com/a/1592899/73070). – Joey May 23 '15 at 13:26