DragDrop() Event Handler assistance needed...
-
I have been working on an application that utilizes the DragDrop Event Handler. To accomplish this, I created a "public" variable named dragPoint which has both X and Y coordinates and made the assignment to that point in the MouseDown() Event handler. The cursor remembers that clicked point on the control from the MouseDown() Event Handler when the user clicks on the control. However, the DragOver() Event handler does not reconcile that point click from the MouseDown() Event handler properly. Could somebody please provide some insights as I am missing some concept here. The code is as follows: private static void _ctrl_DragOver(object sender, DragEventArgs e) { try { if(DragDropHandler.CanDropHere((Control)sender, e.Data)) { Control cthis = (Control)sender; e.Effect = DragDropEffects.Move; Control ctrl = DragDropHandler.GetControl(e.Data, false, true); // Here is the code with the problem Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y)); ctrl.Left = NewLocationX + 2; ctrl.Top = NewLocation.Y + 2; // End problem code above } else { // Error Message } } } Note: I tried subtracting away the dragPoint.X from the "new Point()" in the cthis.PointToClient() but that only causes the cursor to change to a circle with a slash through it indicating a mathematical conceptual error somewhere. I also tried to add the dragPoint.X to the ctrl.Left and the ctrl.Top, and while that does work, it causes the cursor to be placed to the left and to the top at a point equal to the point that the control is clicked in the MouseDown() Event. When I tried to subtract the dragPoint.X and dragPoint.Y from the ctrl.Left and ctrl.Top statements, then the cursor changes again to a circle with a slash through it. What concept have I missed here? Should I be using PointToClient() or PointToScreen() ot something else to get the cursor to drag from the point that the user clicks on the control? // Alternate code tried Point NewLocation = cthis.PointToClient(new Point(e.X - dragPoint.X, e.Y - dragPoint.Y)); ctrl.Left = NewLocationX - dragPoint.X; ctrl.Top = NewLocation.Y - dragPoint.Y; // End alternate code tried :confused::confused::confused: -- modified at 18:31 Saturday 6th May, 2006
-
I have been working on an application that utilizes the DragDrop Event Handler. To accomplish this, I created a "public" variable named dragPoint which has both X and Y coordinates and made the assignment to that point in the MouseDown() Event handler. The cursor remembers that clicked point on the control from the MouseDown() Event Handler when the user clicks on the control. However, the DragOver() Event handler does not reconcile that point click from the MouseDown() Event handler properly. Could somebody please provide some insights as I am missing some concept here. The code is as follows: private static void _ctrl_DragOver(object sender, DragEventArgs e) { try { if(DragDropHandler.CanDropHere((Control)sender, e.Data)) { Control cthis = (Control)sender; e.Effect = DragDropEffects.Move; Control ctrl = DragDropHandler.GetControl(e.Data, false, true); // Here is the code with the problem Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y)); ctrl.Left = NewLocationX + 2; ctrl.Top = NewLocation.Y + 2; // End problem code above } else { // Error Message } } } Note: I tried subtracting away the dragPoint.X from the "new Point()" in the cthis.PointToClient() but that only causes the cursor to change to a circle with a slash through it indicating a mathematical conceptual error somewhere. I also tried to add the dragPoint.X to the ctrl.Left and the ctrl.Top, and while that does work, it causes the cursor to be placed to the left and to the top at a point equal to the point that the control is clicked in the MouseDown() Event. When I tried to subtract the dragPoint.X and dragPoint.Y from the ctrl.Left and ctrl.Top statements, then the cursor changes again to a circle with a slash through it. What concept have I missed here? Should I be using PointToClient() or PointToScreen() ot something else to get the cursor to drag from the point that the user clicks on the control? // Alternate code tried Point NewLocation = cthis.PointToClient(new Point(e.X - dragPoint.X, e.Y - dragPoint.Y)); ctrl.Left = NewLocationX - dragPoint.X; ctrl.Top = NewLocation.Y - dragPoint.Y; // End alternate code tried :confused::confused::confused: -- modified at 18:31 Saturday 6th May, 2006