动态添加 items to PopupMenu

引用自http://stackoverflow.com/questions/10175140/adding-items-to-popupmenu

DevExpress.XtraBars.BarManager barManager1;
            DevExpress.XtraBars.PopupMenu buttonContextMenu;

            barManager1 = new DevExpress.XtraBars.BarManager();
            /// Gets or sets the container for bar controls that are managed by the current BarManager.
            barManager1.Form = this;
            buttonContextMenu = new DevExpress.XtraBars.PopupMenu(barManager1);
            buttonContextMenu.Name = "subViewContextMenu";

            for (int i = 0; i < 10; i++)
            {
                DevExpress.XtraBars.BarButtonItem btnitem = new DevExpress.XtraBars.BarButtonItem();
                btnitem.Caption = "未来" + i.ToString();
                btnitem.Id = i;
                btnitem.Name = "barButtonItem1" + i;
                btnitem.ItemClick += btnitem_ItemClick;

                //add items to barmanager
                barManager1.Items.Add(btnitem);
                //create links between bar items and popup
                buttonContextMenu.ItemLinks.Add(barManager1.Items["barButtonItem1" + i]);
            }

            //finally set the context menu to the control or use the showpopup method on right click of control
            barManager1.SetPopupContextMenu(btnshowPop, buttonContextMenu);
原文地址:https://www.cnblogs.com/shangshen/p/6433099.html