I have make a ToolStrip works like windows task bar. When user opens a new form, a label with form's icon appears on ToolStrip as new label item. I also have a button that closes all forms at once. But I want to remove every relevant label too, so I added this into the click event...
For Each mdichildlabel As ToolStripLabel In Me.BottomToolStrip.Items
If mdichildlabel.Name = "NewLabel" Then
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Doesn't work doesn't tell us what you are seeing that is not working.
Generally, you can't modify a collection while for-eaching it because of the changing index positions. Try iterating over it backwards:
For i As Integer = Me.BottomToolStrip.Items.Count - 1 to 0 Step -1 If Me.BottomToolStrip.Items(i).Name = "NewLabel" Then Me.BottomToolStrip.Items.RemoveAt(i) End If Next