Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Assigning a control back to the main form in the DragOver method... [modified]

Assigning a control back to the main form in the DragOver method... [modified]

Scheduled Pinned Locked Moved C#
questionhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    new_phoenix 0
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups