By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,961 Members | 2,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,961 IT Pros & Developers. It's quick & easy.

how to make control moveable from mouse in windows application.

P: n/a
I have one panel in which i have my control, know i want to move it at run
time using mouse.
Sep 16 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Atul Rane" wrote:
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

--
Happy Coding!
Morten Wennevik [C# MVP]

Sep 16 '08 #2

P: n/a


"Morten Wennevik [C# MVP]" wrote:
>
"Atul Rane" wrote:
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

--
Happy Coding!
Morten Wennevik [C# MVP]
Thanks Morten
Sep 16 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.