/// <summary> /// This method runs when the update finishes /// </summary> public override void OnSeriesUpdatedFinish() { foreach (var inactive in Splitters .Where(s => s.SplitterCollectorIndex < SplittersCollector).ToList()) { Figure.Segments.Remove(inactive.Left); Figure.Segments.Remove(inactive.Bottom); Figure.Segments.Remove(inactive.Right); Splitters.Remove(inactive); } }
public override void Reorder(List <Panel> panels, List <int> indexes) { SuspendLayout(); for (int i = 0; i < panels.Count; i++) { int panelIndex = this.Controls.GetChildIndex(panels[i]); Splitter splitter = this.Controls[panelIndex + noOfControlsCreatedForEachPanel - 1] as Splitter; // get the panel below splitter int newIndex = GetChildIndexByPanelIndex(Panels.Count - 1, indexes[i]); // when new position is below the current position, need to insert at new positon + 1 // i.e when splitter is moved from 2 to 8 it should be inserted at 9 // but when it is moved from 8 to 2 it should be inserted at 2 . // Some explanation ...(Strange .net behavior !!) //Say that we have 5 splitter(s1..s5) and panels (p1…p5) , with z order as shown // Move from 2 to 8 : // p1, s1, p2 , s2 ..... p5, s5 // Now when we move p2 (at 2) to index 8 , all the controls after index 3(s2) to index 8(p5) will be moved upward by 1. // p1, s1, s2, p3, s3, p4, s4, p5, p2 ,s5 (not expected behavior) // Now as you can see when we move from 2 to 8 , P2 is inserted between P5 and S5 which is not desired behavior for us. //So, we need to insert P2 at index 9 and then S2 at 9 again so that splitter and panels remain together. //Now consider the case when we move from 8 to 2. //When we move from 8 to 2, all controls from 2 to 7 are moved downwards. // So controls are : // p1, s1, p5, p2, s2, p3, s3, p4, s4, s5 (expected behavior ) // (If we will move at 3 using +1 logic it will result in incorrect behavior ) if (newIndex > panelIndex) { newIndex += noOfControlsCreatedForEachPanel - 1; } if (newIndex != panelIndex) { Controls.SetChildIndex(splitter, newIndex); // add splitter at //correct position Splitters.Remove(splitter); Splitters.Insert(indexes[i], splitter); if (newIndex > panelIndex) { newIndex -= noOfControlsCreatedForEachPanel - 1; } Controls.SetChildIndex(panels[i], newIndex); // add panel at correct //position Panels.Remove(panels[i]); Panels.Insert(indexes[i], panels[i]); } } ResumeLayout(); }