Smrf.NodeXL.ExcelTemplate.WorksheetContextMenuManager.AddContextMenuItem C# (CSharp) Méthode

AddContextMenuItem() protected méthode

protected AddContextMenuItem ( CommandBarPopup oCommandBarPopup, String sText, Int32 iClickedID, _CommandBarButtonEvents_ClickEventHandler oEventHandler ) : System.Windows.Forms.CommandBarButton
oCommandBarPopup CommandBarPopup
sText String
iClickedID System.Int32
oEventHandler _CommandBarButtonEvents_ClickEventHandler
Résultat System.Windows.Forms.CommandBarButton
    AddContextMenuItem
    (
        CommandBarPopup oCommandBarPopup,
        String sText,
        Int32 iClickedID,
        _CommandBarButtonEvents_ClickEventHandler oEventHandler
    )
    {
        Debug.Assert(oCommandBarPopup != null);
        Debug.Assert( !String.IsNullOrEmpty(sText) );
        Debug.Assert(oEventHandler != null);
        AssertValid();

        // Important Note:
        //
        // Do not use CommandBarButton.Tag to store the clicked ID.  There is
        // a bug in VSTO 2008 that causes all CommandBarButtons with the same
        // Tag to fire their Click events when one such CommandBarButton is
        // clicked.  Here is an online posting discussing this:
        //
        // http://excelusergroup.org/forums/p/700/2153.aspx
        //
        // Instead of the Tag, use the CommandBarButton.Parameter property.

        CommandBarButton oCommandBarButton =
            (CommandBarButton)oCommandBarPopup.Controls.Add(
                MsoControlType.msoControlButton, 1, iClickedID.ToString(),
                Missing.Value, true);

        oCommandBarButton.Caption = sText;
        oCommandBarButton.Style = MsoButtonStyle.msoButtonCaption;
        oCommandBarButton.Enabled = false;
        oCommandBarButton.Click += oEventHandler;

        return (oCommandBarButton);
    }