By the way, if I use the following code instead, which adds Buttons to a Panel instead of ToolStrips to a ToolStripPanel, then it works just fine!
vb.net Code:
  1. Public Class ButtonPanel
  2.     Inherits Panel
  3.  
  4.     Private _Buttons As New ButtonCollection(Me)
  5.     Public ReadOnly Property Buttons() As ButtonCollection
  6.         Get
  7.             Return _Buttons
  8.         End Get
  9.     End Property
  10.  
  11. End Class
  12.  
  13. Public Class ButtonCollection
  14.     Inherits System.Collections.ObjectModel.Collection(Of Button)
  15.  
  16.     Private _panel As ButtonPanel
  17.     Public Sub New(ByVal panel As ButtonPanel)
  18.         _panel = panel
  19.     End Sub
  20.  
  21.     Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As System.Windows.Forms.Button)
  22.         MyBase.InsertItem(index, item)
  23.         _panel.Controls.Add(item)
  24.     End Sub
  25.  
  26. End Class
Now I can use the Buttons property of this panel to add/remove them via a collection editor window (very similar to how you can add/remove TabPages to a TabControl).

This code is exactly the same as above... The only difference is that I replaced the ToolStripPanel with Panel* and ToolStrip with Button. I can't figure out why this works with buttons but not with ToolStrips.


*The problem is not caused by using a ToolStripPanel instead of a Panel. I cannot add ToolStrips to a normal Panel this way either.