コード例 #1
0
        private void ItemMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            BaseItem item = sender as BaseItem;

            if (item == null || item.Category != "Shortcut")
            {
                return;
            }
            // Show context menu for regular menu item...
            m_FavoriteContext = new ButtonItem();
            // Remember the item that this context menu is working with
            m_FavoriteContext.Tag = item;
            ButtonItem context = new ButtonItem("bOpenShortcut");

            context.Text = "Open";
            m_FavoriteContext.SubItems.Add(context);
            context            = new ButtonItem("bEditShortcut");
            context.Text       = "Edit Shortcut";
            context.BeginGroup = true;
            m_FavoriteContext.SubItems.Add(context);
            context      = new ButtonItem("bDeleteShortcut");
            context.Text = "Delete";
            m_FavoriteContext.SubItems.Add(context);
            // Order of following commands is important so Favorites popup menu stays open
            // If RegisterPopup is called before PopupMenu the Favorites menu will be closed
            m_FavoriteContext.PopupMenu(Control.MousePosition);
            dotNetBarManager1.RegisterPopup(m_FavoriteContext);
        }
コード例 #2
0
        private void PopupMenu(object sender, System.EventArgs e)
        {
            if (m_PopupFromCode == null)
            {
                CreatePopupMenu();
            }

            // Apply style
            DevComponents.DotNetBar.eDotNetBarStyle style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;
            if (((DevComponents.Editors.ComboItem)cboStyle.SelectedItem).Text != "Office2003")
            {
                style = DevComponents.DotNetBar.eDotNetBarStyle.VS2005;
            }
            m_PopupFromCode.Style = style;

            // MUST ALWAYS register popup with DotNetBar Manager if popup does not belong to ContextMenus collection
            dotNetBarManager1.RegisterPopup(m_PopupFromCode);

            // Place the menu just below the button
            Control ctrl = sender as Control;
            Point   p    = this.PointToScreen(new Point(ctrl.Left, ctrl.Bottom));

            m_PopupFromCode.PopupMenu(p);
        }