My app dynamically开发者_如何学Python adds/removes menu items at run-time. My removal code looks like this:
while (menu.DropDownItems.Count > 0) {
menu.DropDownItems[0].Dispose();
}
This works fine, because ToolStripItem.Dispose says this.Owner.Items.Remove(this);
(verified with ILSpy).
My question is: Is it good form to rely on the fact that ToolStripItem.Dispose also removes the item from the menu? The documentation for ToolStripItem.Dispose does not mention this fact.
This is actually the default behavior of the Control
class, so it goes a bit further than just ToolStripItem
. I am using this method in my code as well.
精彩评论