Exemplo n.º 1
0
        private void InitializeToolBar()
        {
            m_items = new ToolBarItemCollection( this );

              // We'll let the toolbar to send us messages for drawing
              SetStyle( ControlStyles.UserPaint, false );

              TabStop = false;

              // Always on top
              Dock = DockStyle.Top;
              Attach();
        }
Exemplo n.º 2
0
        void IChevron.Show( Control control, Point point )
        {
            if( m_bShowChevron )
              {
            // Don't try to show it again
            // if we are showing it already
            return;
              }

              m_bShowChevron = true;
              ToolBarItemCollection chevronItems = new ToolBarItemCollection();
              ToolBarItem   lastItem;
              Size          size = ClientSize;
              int           currentCount = 0;
              bool          addItem = true;
              bool          hasComboBox = false;

              for( int i = 0; i < m_items.Count; i++ )
              {
            bool IsSeparator = false;

            RECT rect = new RECT();
            WindowsAPI.SendMessage(Handle, ( int )ToolBarMessages.TB_GETITEMRECT, i, ref rect);

            if( rect.right > size.Width )
            {
              ToolBarItem item = m_items[i];
              if( item.ComboBox != null ) hasComboBox = true;

              IsSeparator = ( item.Style == ToolBarItemStyle.Separator );

              if( item.Visible )
              {
            if( ( !IsSeparator  ) || ( chevronItems.Count != 0 ) )
            {
              // don't add it if previous item was a separator
              currentCount = chevronItems.Count;

              if( currentCount > 0 )
              {
                lastItem = chevronItems[currentCount-1];
                if( lastItem.Style == ToolBarItemStyle.Separator && IsSeparator )
                {
                  addItem = false;
                }
              }

              if( addItem ) chevronItems.Add( item );
              addItem = true;
            }
              }
            }
              }

              // Don't show a separator as the last item of the context menu
              int itemsCount = chevronItems.Count;

              if( itemsCount > 0 )
              {
            lastItem = chevronItems[itemsCount-1];
            if( lastItem.Style == ToolBarItemStyle.Separator )
            {
              chevronItems.RemoveAt( itemsCount-1 );
            }
              }

              chevronMenu.Items = chevronItems;
              chevronMenu.Style = VisualStyle.IDE;
              chevronMenu.TrackPopup(control.PointToScreen( point ));

              // Need to reparent the combobox to this toolbar in case
              // there was a combobox that was displayed by the popup menu
              if( hasComboBox )
              {
            // Run the logic for combobox visibility before reposition it
            ToolbarSizeChanged( new NMREBARCHILDSIZE() );

            for ( int i = 0; i < m_items.Count; i++ )
            {
              ToolBarItem item = m_items[i];

              if( item.Style == ToolBarItemStyle.ComboBox && item.ComboBox != null )
              {
            WindowsAPI.SetParent( item.ComboBox.Handle, Handle );
            WindowsAPI.ShowWindow( item.ComboBox.Handle, ( short )ShowWindowStyles.SW_SHOWNOACTIVATE );
            ComboBoxBase cbb = ( ComboBoxBase )item.ComboBox;
            cbb.ToolBarUse = true;
            UpdateItem( i );
            cbb.Invalidate();
              }
            }
              }

              m_bShowChevron = false;
        }