Exemplo n.º 1
0
    private   void AddSubMenu( MenuCommand parentMenuCommand, MenuItemExCollection items )
    {
      for ( int i = 0; i < items.Count; i++ )
      {
        // I know these menu items are actually MenuItemExs
        MenuItemEx item = (MenuItemEx)items[i];

        Bitmap bmp = ( item.Icon != null ) ? (Bitmap)item.Icon : 
          ( ( item.ImageList != null ) ? 
          (Bitmap)item.ImageList.Images[ item.ImageIndex ] : null ); 

        EventHandler hndl = item.ClickHandler;

        // if menu item does not have any ClickHandler then attach own
        if( hndl == null )
        {
          hndl = new EventHandler( RaiseMenuItemClick );
        }

        MenuCommand currentMenuCommand = new MenuCommand(item.Text, bmp,
          (Shortcut)item.Shortcut, hndl, item);

        currentMenuCommand.Checked = item.Checked;
        currentMenuCommand.Enabled = item.Enabled;

        parentMenuCommand.MenuCommands.Add(currentMenuCommand);
        
        if ( item.MenuItems.Count > 0 )
        {
          AddSubMenu( currentMenuCommand, item.MenuItems );
        }
      }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Attach custom collection of menu items to context menu. Any changes
    /// of collection context will be catched by context menu. Context menu
    /// will be always up to date
    /// </summary>
    /// <param name="items"></param>
    public void AttachOnMenuCollection( MenuItemExCollection items )
    {
      if( m_attach != null ) Detach();

      m_attach = items;
      m_attach.Changed += new EventHandler( OnAttacherDataChanged );

      // get items from collection
      UpdateContextMenuItems( m_attach );
    }
 /// <summary>
 /// Create class and attach it to collection of items
 /// </summary>
 /// <param name="items">Collection of Menu Items</param>
 /// <param name="bAttach">TRUE - attach class to collection, otherwise 
 /// skip any collection context changes</param>
 public CommandBarMenu( MenuItemExCollection items, bool bAttach )
 {
     if( bAttach == true )
       {
     AttachOnMenuCollection( items );
       }
       else
       {
     UpdateContextMenuItems( items );
       }
 }
Exemplo n.º 4
0
        private void Initialize( Bitmap bitmap, Shortcut shortcut, EventHandler handler, 
      ImageList list, int imageIndex )
        {
            m_items = new MenuItemExCollection();
              m_items.Changed += new EventHandler( OnCollectionChange );
              m_items.Cleared += new CollectionClear( OnCollectionClear );

              OwnerDraw = true;
              this.Shortcut = shortcut;
              icon = bitmap;
              clickHandler = handler;
              imageList = list;
              this.imageIndex = imageIndex;
        }
Exemplo n.º 5
0
        private MenuItem FindShortcutItem( MenuItemExCollection m_items, Keys keys )
        {
            MenuItem resultItem = null;
              foreach ( MenuItemEx item in m_items  )
              {
            if( (( int )item.Shortcut == ( int )keys) && ( item.Enabled ) && ( item.Visible ) )
            {
              return item;
            }
            else
            {
              resultItem =  FindShortcutItem( item.MenuItems, keys );
              if( resultItem != null ) break;
            }
              }

              return resultItem;
        }
Exemplo n.º 6
0
 public MainMenuEx()
 {
     m_items = new MenuItemExCollection();
       m_items.Changed += new EventHandler( OnCollectionChange );
 }
Exemplo n.º 7
0
 private void Initialize( Image image, string text, EventHandler clickHandler, 
   Keys shortCut, string toolTip, int imageListIndex )
 {
   m_imgIcon = image;
   m_strText = text;
   
   if( clickHandler != null )
   {
     this.Click += clickHandler;
   }
   
   m_sCut = shortCut;
   m_strToolTip = toolTip;
   
   m_arrItems   = new MenuItemExCollection();
   m_mnuSubMenu = new CommandBarMenu( m_arrItems, true );
   m_iImageIndex = imageListIndex;
 }
        /// <summary>
        /// Helper Method which update internal Collection of ContextMenu
        /// </summary>
        /// <param name="coll"></param>
        private void UpdateContextMenuItems( MenuItemExCollection coll )
        {
            MenuItems.Clear();

              for( int i = 0; i<m_attach.Count; i++ )
              {
            MenuItems.Add( ( MenuItemEx )m_attach[ i ] );
              }
        }