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!
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).vb.net Code:
Public Class ButtonPanel Inherits Panel Private _Buttons As New ButtonCollection(Me) Public ReadOnly Property Buttons() As ButtonCollection Get Return _Buttons End Get End Property End Class Public Class ButtonCollection Inherits System.Collections.ObjectModel.Collection(Of Button) Private _panel As ButtonPanel Public Sub New(ByVal panel As ButtonPanel) _panel = panel End Sub Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As System.Windows.Forms.Button) MyBase.InsertItem(index, item) _panel.Controls.Add(item) End Sub End Class
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.




Reply With Quote