Skip to content

Commit

Permalink
[TabControl] Fix setting tab pages via collection indexer. (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst authored Jul 15, 2023
1 parent 5b8fa9b commit 096b976
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/Modern.Forms/ControlCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ private static void Copy (ControlCollection sourceList, int sourceIndex, Control
destinationIndex += length;

for (; length > 0; length--)
destinationList[--destinationIndex] = sourceList[--sourceIndex];
destinationList.control_list[--destinationIndex] = sourceList[--sourceIndex];
} else {
for (; length > 0; length--)
destinationList[destinationIndex++] = sourceList[sourceIndex++];
destinationList.control_list[destinationIndex++] = sourceList[sourceIndex++];
}
}

Expand Down Expand Up @@ -459,7 +459,12 @@ public virtual Control this[int index] {
Debug.Assert (control is not null, "Why are we returning null controls from a valid index?");
return control;
}
set => control_list[index] = value;
}

// Setter required by IList<T>, but we don't want users to be able to set Controls this way
Control IList<Control>.this[int index] {
get => this[index];
set => throw new NotSupportedException ();
}

/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions src/Modern.Forms/TabPageCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ protected override void SetItem (int index, TabPage item)
base.SetItem (index, item);

item.Visible = false;
owner.Controls[index] = item;
tab_strip.Tabs[index] = item.TabStripItem;

owner.SuspendLayout ();
RemoveItem (index);
InsertItem (index, item);
owner.ResumeLayout ();
}
}
}

0 comments on commit 096b976

Please sign in to comment.