Hi team.
I am trying to move a panel type object (panel child) that is inside another panel type object (Parent panel A) to another panel (Parent panel B), these panels were created dynamically.
I know that in this case it is necessary to obtain the sender object of the parents panels and even there everything well, when I move the child object within its parent panel, it is done without problem, but when I try to move it between parent panels, it does not perform any action . Can you help me in showing me where my mistake is? I attached the generated code.
Thank you in advance and effort.
What I have tried:
This is to get (cut)
Private Sub ToolStripMenuItem3_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem3.Click
clickedPanel = DirectCast(DirectCast(DirectCast(sender, ToolStripMenuItem).Owner, ContextMenuStrip).SourceControl, Panel)
p1Name = clickedPanel.Name
paParent = clickedPanel.parent
End Sub
This is to do (paste)
Private Sub ToolStripMenuItem4_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem4.Click
clickedPanel = DirectCast(DirectCast(DirectCast(sender, ToolStripMenuItem).Owner, ContextMenuStrip).SourceControl, Panel)
p2Name = clickedPanel.Name
pbParent = clickedPanel.parent
Call Swap()
End Sub
This is to do the swap.
Private Sub Swap()
'' build the panel names
Dim varA As String = p1Name.ToString
Dim varC As String = p2Name.ToString
Dim PanelParent As Panel = paParent
Dim PanelParent_b As Panel = pbParent
Dim p3 = DirectCast(PanelParent.Controls.Find(p1Name, True).FirstOrDefault(), Panel)
If p3 Is Nothing Then Throw New ArgumentException("index1")
Dim p4 = DirectCast(PanelParent_b.Controls.Find(p2Name, True).FirstOrDefault(), Panel)
If p4 Is Nothing Then Throw New ArgumentException("index2")
Dim positionA As Integer = Panel1.AutoScrollPosition.X
Panel1.AutoScroll = False
Dim temp = p4.Location
p4.Location = p3.Location
p3.Location = temp
Panel1.AutoScroll = True
Panel1.AutoScrollPosition = New Point(positionA, Panel1.VerticalScroll.Maximum)
End Sub
Try to do this too.
p3.Location = New Point(p3.Location.X, p3.Location.Y)
PanelParent.Controls.Add(p3)
p4.Location = New Point(p4.Location.X, p4.Location.Y)
PanelParent_b.Controls.Add(p4)