public bool CloseTab(Tab tab) { if (!AllowNoTabs && Tabs.Count == 1) { return(false); } if (animation == null || !animation.Enabled) { animation = new Animation(); } else { return(false); } int i = Tabs.IndexOf(tab); if (i == -1) { return(false); } if (Tabs.Count == 0) { CurrentTab = null; } else if (CurrentTab == tab) { CurrentTab = Tabs[i == 0 ? i + 1 : i - 1]; } // Animation Tabs[i].SendToBack(); CurrentTab.BringToFront(); int width = pnlTabs.Width; animation.Tick += (_, value) => { Tabs[i].Top = (int)(value * Tabs[i].Height); if (i + 1 < Tabs.Count) { Tabs[i + 1].Left = Tabs[i].Right - (int)(value * Tabs[i].Width); } for (int j = i + 2; j < Tabs.Count; j++) { Tabs[j].Left = Tabs[j - 1].Right; } pnlTabs.Width = width - (int)(value * Tabs[i].Width); addButton.Left = pnlTabs.Right; }; animation.Complete += (_, evt) => { Tabs.RemoveAt(i); if (TabClosed != null) { TabClosed(this, tab); } }; animation.Start(); return(true); }