A class to display a cool custom context menu
Наследование: System.Windows.Forms.Form
Пример #1
0
 private void yamuiCharButton1_Click(object sender, EventArgs e)
 {
     var menu = new YamuiMenu(Cursor.Position, new List<YamuiMenuItem> {
         new YamuiMenuItem {
             ItemName = "zefefzefzef zedf item 1",
             Children = new List<YamuiMenuItem> {
                 new YamuiMenuItem {ItemName = "child 1"}
             }
         },
         new YamuiMenuItem {
             ItemName = "item 2",
         },
         new YamuiMenuItem {
             ItemName = "item 3",
             Children = new List<YamuiMenuItem> {
                 new YamuiMenuItem {ItemName = "child 1"},
                 new YamuiMenuItem {ItemName = "child 2"}
             }
         }
     });
     menu.Show();
 }
Пример #2
0
        /// <summary>
        /// an item has been pressed
        /// </summary>
        private void OnItemPressed()
        {
            var item = _content[_selectedIndex];

            // item has children, open a new menu
            if (item.Children != null && item.Children.Any())
            {
                _childMenu = new YamuiMenu(Location, item.Children)
                {
                    IamMain     = false,
                    _parentMenu = this
                };
                _childMenu.SetPosition(new Rectangle(Location.X + Width, Location.Y + Controls[_selectedIndex].Top, Width, Height), _reverseX, _reverseY);
                _childMenu.Show();
            }
            else
            {
                // exec action and close the menu
                item.Do();
                CloseAll();
            }
        }
Пример #3
0
 /// <summary>
 /// The historic button shows a menu that allows the user to select a previously selected folders
 /// </summary>
 private void BtHistoricOnButtonPressed(object sender, EventArgs eventArgs)
 {
     List<YamuiMenuItem> itemList = new List<YamuiMenuItem>();
     foreach (var path in Config.Instance.CompileDirectoriesHistoric.Split(',')) {
         if (!string.IsNullOrEmpty(path)) {
             itemList.Add(new YamuiMenuItem {
                 ItemImage = ImageResources.FolderType, ItemName = path, OnClic = () => {
                     if (IsHandleCreated) {
                         BeginInvoke((Action)delegate {
                             fl_directory.Text = path;
                             SaveHistoric();
                         });
                     }
                 }
             });
         }
     }
     if (itemList.Count > 0) {
         var menu = new YamuiMenu(Cursor.Position, itemList);
         menu.Show();
     }
 }
Пример #4
0
 /// <summary>
 /// an item has been pressed
 /// </summary>
 private void OnItemPressed()
 {
     var item = _content[_selectedIndex];
     // item has children, open a new menu
     if (item.Children != null && item.Children.Any()) {
         _childMenu = new YamuiMenu(Location, item.Children) {
             IamMain = false,
             _parentMenu = this
         };
         _childMenu.SetPosition(new Rectangle(Location.X + Width, Location.Y + Controls[_selectedIndex].Top, Width, Height), _reverseX, _reverseY);
         _childMenu.Show();
     } else {
         // exec action and close the menu
         item.Do();
         CloseAll();
     }
 }
Пример #5
0
        /// <summary>
        /// Show a given menu
        /// </summary>
        public static void ShowMenuAtCursor(List<YamuiMenuItem> menuList, string menuTitle, string menuLogo = "logo16x16", int minSize = 180)
        {
            try {
                // Close any already opened menu
                ForceCloseMenu();

                // open requested menu
                var copyMenuList = menuList.ToList();
                copyMenuList.Insert(0, new YamuiMenuItem { IsSeparator = true });

                var menu = new YamuiMenu(Cursor.Position, copyMenuList, "<div class='contextMenuTitle'><img src='" + menuLogo + "' width='16' Height='16' style='padding-right: 5px; padding-top: 1px;'>" + menuTitle + "</span>", minSize);
                menu.Show();
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error in ShowMenuAtCursor");
            }
        }