Example #1
0
 /// <summary>
 /// Create the event used when a menu item has been selected.
 /// </summary>
 /// <param name="item">The selected item.</param>
 public MenuItemSelectEventArgs(MenuItem item)
 {
     //Pass along the data.
     _Item = item;
 }
Example #2
0
        /// <summary>
        /// A menu item has been selected.
        /// </summary>
        /// <param name="item">The selected menu item.</param>
        private void MenuItemSelectInvoke(MenuItem item)
        {
            //Save the selected item.
            _SelectedItem = item;

            //If someone has hooked up a delegate to the event, fire it.
            if (MenuItemSelect != null) { MenuItemSelect(this, new MenuItemSelectEventArgs(item)); }
        }
Example #3
0
        /// <summary>
        /// Move an item upwards in the menu.
        /// </summary>
        /// <param name="item">The menu item to move.</param>
        /// <returns>Whether the operation was succesful or not. For instance if the node already is at the top, this method will return false.</returns>
        public bool MoveNodeUp(MenuItem item)
        {
            //First see if the item actually exists in this list.
            if (_Items.Exists(n => (n.Equals(item))))
            {
                //Get the index position of the item.
                int index = _Items.FindIndex(i => (i.Equals(item)));

                //If the item can climb in the list.
                if (index != 0)
                {
                    //Remove the item from the list.
                    _Items.Remove(item);
                    //Insert the item at one step up from its past position in the list.
                    _Items.Insert((index - 1), item);

                    //Wrap it all up by returning true.
                    return true;
                }
                //Otherwise return false.
                else { return false; }
            }
            //Otherwise return false.
            else { return false; }
        }
Example #4
0
 /// <summary>
 /// Subscribe to an item's events.
 /// </summary>
 private void AddItemEvents(MenuItem item)
 {
     //Hook up some events.
     item.MouseClick += OnMenuItemClick;
     item.ItemSelect += OnMenuOptionSelect;
 }
Example #5
0
 /// <summary>
 /// Insert a menu item.
 /// </summary>
 /// <param name="index">The index of where to insert the menu item.</param>
 /// <param name="item">The menu item to insert.</param>
 public void InsertMenuItem(int index, MenuItem item)
 {
     //Insert the item to the list.
     _Items.Insert(index, item);
     //Hook up some events.
     AddItemEvents((MenuItem)_Items[_Items.Count - 1]);
 }