コード例 #1
0
        /// <summary>
        /// Add a item at a certain position to a sub menu of this item. This method will create a submenu if there is no one present.
        /// </summary>
        /// <param name="index">The index in the menu list the item should be added.</param>
        /// <param name="type">The type of the item.</param>
        /// <param name="text">The text of the item.</param>
        /// <returns>The item itself.</returns>
        public SystemMenuItem InsertSubItem(int index, SystemMenuItemType type, string text = "")
        {
            List <int> usedIDs = SysMenu.GetUsedIDs();
            int        id      = 0;

            while (usedIDs.Contains(id))
            {
                id++;
            }

            IntPtr p = SubMenu;

            if (p == IntPtr.Zero)
            {
                p       = SysMenuAPI.CreateMenu();
                SubMenu = p;
            }

            SystemMenuItem itm = new SystemMenuItem(SysMenu, p, id);

            SubItems.Insert(index, itm);
            SysMenuAPI.InsertMenu(p, index, SysMenuAPI.Flags.MF_BYPOSITION | (type == SystemMenuItemType.STRING ? SysMenuAPI.MenuTypes.MF_STRING : SysMenuAPI.MenuTypes.MF_SEPARATOR), id, text);
            return(itm);
        }
コード例 #2
0
        /// <summary>
        /// Add a item to a sub menu of this item. This method will create a submenu if there is no one present.
        /// </summary>
        /// <param name="type">The type of the item.</param>
        /// <param name="text">The text of the item.</param>
        /// <returns>The item itself.</returns>
        public SystemMenuItem AddSubItem(SystemMenuItemType type, string text = "")
        {
            List <int> usedIDs = SysMenu.GetUsedIDs();
            int        id      = 0;

            while (usedIDs.Contains(id))
            {
                id++;
            }

            IntPtr p = SubMenu;

            if (p == IntPtr.Zero)
            {
                p       = SysMenuAPI.CreateMenu();
                SubMenu = p;
            }

            SystemMenuItem itm = new SystemMenuItem(SysMenu, p, id);

            SubItems.Add(itm);
            SysMenuAPI.AppendMenu(p, type == SystemMenuItemType.STRING ? SysMenuAPI.MenuTypes.MF_STRING : SysMenuAPI.MenuTypes.MF_SEPARATOR, id, text);
            return(itm);
        }