namespace System.Windows.Forms { public partial class TabControl : Control { protected new System.Windows.Controls.TabControl control { get; } public TabPageCollection TabPages { get; } private TabAppearance appearance; public TabAppearance Appearance { get => appearance; set { appearance = value; control.BorderThickness = new System.Windows.Thickness(value == TabAppearance.Normal ? 1 : 0); if (value != TabAppearance.Normal) control.Background = null; } } private System.Drawing.Size itemSize; public System.Drawing.Size ItemSize { get => itemSize; set { itemSize = value; for (int i = 0; i < control.Items.Count; i++) { var item = (System.Windows.Controls.TabItem)control.Items[i]; item.Width = value.Width; item.Height = value.Height; } } } public bool Multiline { get; set; } // TODO? it's multiline by default public TabSizeMode SizeMode { get; set; } public int SelectedIndex { get => control.SelectedIndex; set => control.SelectedIndex = value; } public TabPage SelectedTab { get => ((System.Windows.Controls.TabItem)control.SelectedItem)?.Tag as TabPage; set => control.SelectedItem = value.control; } public event TabControlCancelEventHandler Selecting; protected virtual void OnSelecting(TabControlCancelEventArgs e) => Selecting?.Invoke(this, e); internal override void AddChild(Control child) { if (child is not TabPage) throw new ArgumentException("child must be of TabPage type"); control.Items.Add(child.control); } internal override void SetChildIndex(Control child, int index) { control.Items.Insert(index, child.control); } internal override void RemoveChild(Control child) { control.Items.Remove(child.control); } public TabControl() { control = new(); SetControl(control); TabPages = new TabPageCollection(Controls); int prevIndex = 0; control.SelectionChanged += (sender, e) => { var args = new TabControlCancelEventArgs(SelectedTab, SelectedIndex, false, TabControlAction.Selecting); OnSelecting(args); if (args.Cancel) { if (SelectedIndex != prevIndex) SelectedIndex = prevIndex; e.Handled = true; } else { prevIndex = SelectedIndex; } }; BackColor = System.Drawing.SystemColors.ControlLightLight; } } }