开发者

Dynamically removing menu items: Dispose calls Remove

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜