Assigning a control back to the main form in the DragOver method... [modified]
-
I need some assistance resolving this issue. In the DragOver method I need to identify the column panel that a control was assigned to before assigning it back again to the main form for the application. The question is, what is the correct approach to assign the control back to the application main form so that the NewLocation() function can assign it to a new location on the main form? Currently, the control only stops dragging when I attempt to drag the control onto the control on that Panel object. I need the control that is dragged to be able to identify which panel the control is being dragged onto and then to reassign the control back to the main form using the PointToScreen() method. Is this even possible?
private static void _ctrlParent_DragOver(object sender, DragEventArgs e)
{...
// Correctly identifies which panel the control it is assigned to so that other code could work correctly. This code provides the need to reassign the control back to the main form again below all within one DragOver method.
ctrl.Parent.Controls.Remove(ctrl);
ctrl.Parent = cthis;
cthis.Controls.Add(ctrl);
Control ctrlPanelContainer = getPanelContainerName(ctrl);
string strPanelContainerName = ctrlPanelContainer.Text;
int intPanelContainerX = ctrlPanelContainer.Left;
int intPanelContainerY = ctrlPanelContainer.Top;
Point pt_parent = new Point(intPanelContainerX, intPanelContainerY); Control panelContainer = ctrl.TopLevelControl.GetChildAtPoint(pt_parent);
strPanelContainerNameMouseUp = panelContainer.Name;// Attempts to assign the control back to the form so that is could drag over another control
frmSolitaireMainForm frm = new frmMainForm();
ctrl.Parent.Controls.Remove(ctrl);
// cthis = frm; // assigns the control to the form.
ctrl.Parent = cthis;
cthis.Controls.Add(ctrl);
string strCthisNew = cthis.Name; // correctly retrieves the form assignment.// Incorrectly places the control back onto the main form.
Point NewLocation = cthis.PointToScreen(new Point(e.X, e.Y));
ctrl.Left = NewLocation.X;
ctrl.Top = NewLocation.Y;
ctrl.BringToFront();...
}modified on Sunday, February 10, 2008 4:26 PM