Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why when I drag Panel shall not be automatically resized in Panel old and appears in the new Panel.

C#
private void PanelMove(object sender, MouseEventArgs e)
       {  Panel p = new Panel();
           p = (Panel)sender;
           p.DoDragDrop(p, DragDropEffects.Link);
       }


       private void PanelDragEnter(object sender, DragEventArgs e)
       {
           currentpanel = (Panel)e.Data.GetData(e.Data.GetFormats()[0]);
           currentpanelParent = (Panel)currentpanel.Parent;
           e.Effect = DragDropEffects.Link;
       }
       private void PanelDrag(object sender, DragEventArgs e)
       {
           var newpanel = new Panel();
           var newpanel2 = new Panel();
           newpanel = (Panel)e.Data.GetData(e.Data.GetFormats()[0]);
           var ParentPanel =(Panel) ((Panel)sender).Parent;
           var totalcontrol = ParentPanel.Controls.Count;
           newpanel.Height = 30;
           newpanel2 = (Panel)sender;

           if (ParentPanel != currentpanelParent)
           {
               ParentPanel.Controls.Add(newpanel);
               ParentPanel.AutoSize = true;
               currentpanelParent.Controls.Remove(currentpanel);
               currentpanel.AutoSize = true;
           }
       }

https://dm2302files.storage.live.com/y2p6qaa6OiOq-PxjDs3Kq6URy2q-mgeDSa_2HakfGsRwbRUL6hVwo7qOPJHRWlsj_K0DQtgOkQzs6j5tvLzPzi0ry-0KMm_OqZGndSYwbks2DIFi3fViSiExqtKN0c0EKlht1Sa1z7i4lCUUcGgF1274Q/Error.jpg?psid=1
Posted
Updated 2-Feb-15 15:13pm
v2

1 solution

I'm not sure what you're trying to achieve but...
You allocate new objects without using them:
C#
Panel p = new Panel()

C#
var newpanel = new Panel();
var newpanel2 = new Panel()


Drag and drop should be initialized by the containing object.
In this case (I think) it is the window?
C#
this p.DoDragDrop(p, DragDropEffects.Link); 

You should look for a specific data in the drop event handler, otherwise it is an unsafe practice.

C#
if(e.Data.GetDataPresent(typeof(Panel)))
newpanel = (Panel)e.Data.GetData(e.Data.GetFormats()[0] typeof(Panel));


Try to firstly remove the panel from it's previous container and then add it to the new one.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900