Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Custom Control: How to move?
 

Custom Control: How to move?

I am creating a custom control by inheriting from System.Windows.Forms.Control.

What is the standard way of implementing a visual move of the control when the user drags it at runtime?  Which event should I be trapping?

Thanks.
K.Kong  Monday, September 26, 2005 11:29 AM
My immediate question is: how do I find out the coordinates of the mouse wrt the container's coordinate space?

Thanks
K.Kong  Tuesday, September 27, 2005 1:11 AM
 Jet Stream wrote:
My immediate question is: how do I find out the coordinates of the mouse wrt the container's coordinate space?

Thanks


mouseMove  MouseEnter
MouseLeave
RemcoJVG  Tuesday, September 27, 2005 10:50 AM
You see, I thought MouseMove was when the mouse is over this object only.  But apparently the MouseMove event will continue to fire even when the mouse moves outside the object so long as the left button was still held down.

The other issue was that the control has to move within its container's coordinate space, but e.X and e.Y of the MouseMove event are referenced to the control's coordinate space.  So in the end, I have to use a global variable to track the old mouse coordinates to determine relative motion instead.

And then so as not to exceed the container's boundaries, I had to test for this.parent.ClientSize.  This is not exactly perfect as there is no way to find out whether the parent has added things such as scrollbars which would reduce the surface area.

I wonder if there is a better way of moving a draggable control.  I don't want to reinvent the wheel.
K.Kong  Tuesday, September 27, 2005 12:38 PM

You can use google to search for other answers

Custom Search

More Threads

• Windows form demostration.
• Project location from Component.ControlDesigner
• User control in designer
• Global exception handler in a UserControl
• Raising events from extern form
• InitializeNewComponent on IDesignerHost.CreateComponent ?
• VS Crashes upon exit
• How to change the look of the Caption Bar?
• Default Enter and Cancel button C# Winforms?
• Panel Control