how to make control moveable from mouse in windows application.

  • Thread starter Thread starter Atul Rane
  • Start date Start date
A

Atul Rane

I have one panel in which i have my control, know i want to move it at run
time using mouse.
 
Atul Rane said:
I have one panel in which i have my control, know i want to move it at run
time using mouse.

Hi Atul,

Handle the MouseMove/MouseDown/MouseUp events on your control. Keep track
of where the mouse was last and calculate the offset when the MouseButton is
down. Adjust the Location property of the Control accordingly. It will
appear to be draggable.

Something along the lines of ...

OnMouseDown
startPosition = current position

OnMouseMove
if(MouseButtons.Left)
newPosition = current position
offset = newPosition - startPosition
adjustLocation(offset)
startPosition = newPosition

OnMouseUp/OnMouseLeave
startPosition = Point.Empty
 
Morten Wennevik said:
Hi Atul,

Handle the MouseMove/MouseDown/MouseUp events on your control. Keep track
of where the mouse was last and calculate the offset when the MouseButton is
down. Adjust the Location property of the Control accordingly. It will
appear to be draggable.

Something along the lines of ...

OnMouseDown
startPosition = current position

OnMouseMove
if(MouseButtons.Left)
newPosition = current position
offset = newPosition - startPosition
adjustLocation(offset)
startPosition = newPosition

OnMouseUp/OnMouseLeave
startPosition = Point.Empty
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top