Beispiel #1
0
        private void BuildMenuItem(bool isContainer)
        {
            IWindowsMenuHost windowsMenuHost = (IWindowsMenuHost)FindParent(typeof(IWindowsMenuHost));

            if (windowsMenuHost != null)
            {
                if (!isContainer)
                {
                    if (GetText() == "-")
                    {
                        _menuItem = windowsMenuHost.MenuContainer.CreateSeparator();
                    }
                    else
                    {
                        _menuItem = windowsMenuHost.MenuContainer.CreateMenuItem(new EventHandler(MenuItemClicked));
                    }
                }
                else
                {
                    _menuItem = windowsMenuHost.MenuContainer.CreateContainer();
                }
                try
                {
                    windowsMenuHost.MenuContainer.AddBarItem(_menuItem, new GetPriorityHandler(GetMenuItemPriority));
                }
                catch
                {
                    _menuItem.Dispose();
                    _menuItem = null;
                    throw;
                }
            }
        }
Beispiel #2
0
 private void RemoveMenuItem()
 {
     if (_menuItem != null)
     {
         IWindowsMenuHost windowsMenuHost = (IWindowsMenuHost)FindParent(typeof(IWindowsMenuHost));
         if (windowsMenuHost != null)
         {
             windowsMenuHost.MenuContainer.RemoveBarItem(_menuItem);
         }
         _menuItem.Dispose();
     }
 }
Beispiel #3
0
 private void EnsureMenu()
 {
     if (_menuContainer == null)
     {
         IWindowsMenuHost windowsMenuHost = (IWindowsMenuHost)FindParent(typeof(IWindowsMenuHost));
         if (windowsMenuHost != null)
         {
             _menuContainer = windowsMenuHost.MenuContainer.CreateContainer();
             ((IWindowsBarButton)_menuContainer).Text = GetMenuText();
             windowsMenuHost.MenuContainer.AddBarItem(_menuContainer, null);
         }
     }
 }