A context menu is created in the scope of the RightClick event, but it
continues to be displayed after that event handler terminates - i.e.
after it has gone out of scope. The code works correctly, but I feel a
bit odd about it. Is there anything to watch out for here?
By the way, the reason I'm creating the menu dynamically every time is
that the menu's contents and enabled-states can change based on what
the user does, and I don't want to duplicate all of that logic for a
separately maintained context menu.
private void map_RightClick(object sender, EventArgs e)
{
ContextMenu myMenu = new ContextMenu();
MenuItem[] items = (MenuItem[]) new ArrayList(
mnuEdit.MenuItems).ToArray(typeof(MenuItem));
foreach (MenuItem item in items)
myMenu.MenuItems.Add(item.CloneMenu());
myMenu.Show(this, this.PointToClient(Control.MousePosition));
}