MenuStrip and ContextMenuStrip

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Johansson

    MenuStrip and ContextMenuStrip

    Hello!

    I have a System.Windows. Forms.MenuStrip with some ToolStripMenuIt em.
    One of these ToolStripMenuIt em is called saveMemberToolS tripMenuItem.
    This one is defined like this this.saveMember ToolStripMenuIt em = new
    System.Windows. Forms.ToolStrip MenuItem();

    I have also a ContextMenuStri p which is connected to the Form.
    In the Form C-tor I have these statements

    ToolStripMenuIt em[] formMenuItemLis t = new ToolStripMenuIt em[1];
    formMenuItemLis t[0] = new ToolStripMenuIt em("Save Member", null,
    new
    System.EventHan dler(saveMember Click));
    ContextMenuStri p formMenu = new ContextMenuStri p();
    formMenu.Items. AddRange(formMe nuItemList);
    ContextMenuStri p = formMenu;
    ContextMenuStri p.Enabled = false;

    Now to my question.
    I have noticed that if I use the previous saveMemberToolS tripMenuItem object
    instead of creating a new one
    in formMenuItemLis t[0] will the saveMemberToolS tripMenuItem be vanished in
    the MenuStrip. I just wonder
    can somebody explain the reason for this in a understandable way.

    //Tony


  • Peter Duniho

    #2
    Re: MenuStrip and ContextMenuStri p

    On Fri, 21 Mar 2008 15:28:51 -0700, Tony Johansson
    <johansson.ande rsson@telia.com wrote:
    [...]
    I have noticed that if I use the previous saveMemberToolS tripMenuItem
    object
    instead of creating a new one
    in formMenuItemLis t[0] will the saveMemberToolS tripMenuItem be vanished
    in
    the MenuStrip. I just wonder
    can somebody explain the reason for this in a understandable way.
    As with controls, your ToolStripMenuIt em can have only a single parent
    (container). If you add it to one parent, it no longer can be a child of
    another parent and will be removed.

    In .NET, these types of objects have a one-to-one relationship between
    parent and child.

    I'm curious why you are using an array of ToolStripMenuIt ems to add just a
    single ToolStripMenuIt em to your ContextMenuStri p. Seems like it'd be
    easier to just add the instance directly.

    Pete

    Comment

    Working...