What am I missing here??? [modified]
-
I am working on an application that implements a drag and drop interface, but when I drag the control with the mouse the control's position does not actually change until the cursor touches the form. That is, if I have a control that is 200 pixels tall by 150 pixels wide and I click the cursor and hold it at pixel 100 and 50, the control does not move until the cursor touches the form, but then the cursor is again positioned at the drag point again. This causes the control to move in jumps. I would like the cursor to remain at the drag position where the cursor was clicked and to drag from that point smoothly without the cursor needing to touch the form. Do I need to somehow resample the control's position so that it moves using the drag point without needing to touch the form? Here is the code
private static void _ctrlParent_DragOver(object sender, DragEventArgs e)
{
try
{
if (DragDropHandler.CanDropHere((Control)sender, e.Data))
{
Control cthis = (Control)sender;
Control cthisParent = ((Control)sender);e.Effect = DragDropEffects.Move; Control ctrl = DragDropHandler.GetControl(e.Data, true, true); if (!(ctrl is IDragDropEnabled)) { return; } if (cthis.Name != ctrl.Name) { ctrl.Parent.Controls.Remove(ctrl); ctrl.Parent = cthis; cthis.Controls.Add(ctrl); ctrl.BringToFront(); } else { return; } Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y)); ctrl.Left = NewLocation.X - dragPoint.X; ctrl.Top = NewLocation.Y - dragPoint.Y; // Do I need to resample the control's position here? } else { e.Effect = DragDropEffects.None; } } catch (System.Exception ex) { MessageBox.Show("Error is " + ex.GetBaseException()); }
}
-- modified at 14:26 Monday 28th May, 2007
-
I am working on an application that implements a drag and drop interface, but when I drag the control with the mouse the control's position does not actually change until the cursor touches the form. That is, if I have a control that is 200 pixels tall by 150 pixels wide and I click the cursor and hold it at pixel 100 and 50, the control does not move until the cursor touches the form, but then the cursor is again positioned at the drag point again. This causes the control to move in jumps. I would like the cursor to remain at the drag position where the cursor was clicked and to drag from that point smoothly without the cursor needing to touch the form. Do I need to somehow resample the control's position so that it moves using the drag point without needing to touch the form? Here is the code
private static void _ctrlParent_DragOver(object sender, DragEventArgs e)
{
try
{
if (DragDropHandler.CanDropHere((Control)sender, e.Data))
{
Control cthis = (Control)sender;
Control cthisParent = ((Control)sender);e.Effect = DragDropEffects.Move; Control ctrl = DragDropHandler.GetControl(e.Data, true, true); if (!(ctrl is IDragDropEnabled)) { return; } if (cthis.Name != ctrl.Name) { ctrl.Parent.Controls.Remove(ctrl); ctrl.Parent = cthis; cthis.Controls.Add(ctrl); ctrl.BringToFront(); } else { return; } Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y)); ctrl.Left = NewLocation.X - dragPoint.X; ctrl.Top = NewLocation.Y - dragPoint.Y; // Do I need to resample the control's position here? } else { e.Effect = DragDropEffects.None; } } catch (System.Exception ex) { MessageBox.Show("Error is " + ex.GetBaseException()); }
}
-- modified at 14:26 Monday 28th May, 2007
Drag-and-drop isn't used to move controls around, it's used for grabbings something (more or less) imaginary (like the representation of some files in an explorer window), and drag them to a control of some kind. If you want to move a control around, you should just capture the mouse on MouseDown, move the control on MouseMove and release the mouse on MouseUp. (Actually, I'm not sure if that is the best way of doing it, but it will get you far closer than using drag-and-drop.)
--- single minded; short sighted; long gone;
-
Drag-and-drop isn't used to move controls around, it's used for grabbings something (more or less) imaginary (like the representation of some files in an explorer window), and drag them to a control of some kind. If you want to move a control around, you should just capture the mouse on MouseDown, move the control on MouseMove and release the mouse on MouseUp. (Actually, I'm not sure if that is the best way of doing it, but it will get you far closer than using drag-and-drop.)
--- single minded; short sighted; long gone;
Guffa: The problem is that I need to be able to drag a control and to drop it onto another control, but in the meantime I need to be able to drag each control from the place where the mouse down click occurs. This drag point is currently retained by the Mouse Down event handler, but the control only moves when the cursor touches the form. This makes the control movement jumpy. I would instead like to be able to move the control from the drag point without the curor touching the form. Do you have any advice? Should I somehow capture the movement of the mouse in the MouseMove event handler? :confused::confused::confused: New_Phoenix
-
Guffa: The problem is that I need to be able to drag a control and to drop it onto another control, but in the meantime I need to be able to drag each control from the place where the mouse down click occurs. This drag point is currently retained by the Mouse Down event handler, but the control only moves when the cursor touches the form. This makes the control movement jumpy. I would instead like to be able to move the control from the drag point without the curor touching the form. Do you have any advice? Should I somehow capture the movement of the mouse in the MouseMove event handler? :confused::confused::confused: New_Phoenix