protected override bool OnClick( Context context )
        {
            Rectangle logicalBounds = context.GetItemBounds( this );
            ButtonSizeKind buttonSizeKind = IdentifyButton( logicalBounds.Size );

            if( buttonSizeKind != ButtonSizeKind.Single )
            {
                Rectangle majorBounds = GetMajorBounds( logicalBounds );
                Rectangle minorBounds = GetMinorBounds( logicalBounds );

                if( minorBounds.Contains( context.RibbonControl.PointToClient( Control.MousePosition ) ) )
                {
                    if( _contextMenuStrip != null )
                    {
                        Screen buttonScreen = Screen.PrimaryScreen;
                        Screen menuScreen = Screen.PrimaryScreen;
                        Point buttonPosn = this.Section.Ribbon.PointToScreen( logicalBounds.Location );
                        Rectangle buttonRect = new Rectangle( buttonPosn, logicalBounds.Size );

                        foreach( Screen screen in Screen.AllScreens )
                        {
                            if( screen.Bounds.Contains( buttonRect ) )
                            {
                                buttonScreen = screen;
                            }
                        }

                        int x = buttonRect.Left, y = buttonRect.Bottom;

                        if( x + _contextMenuStrip.Bounds.Width > buttonScreen.WorkingArea.Right )
                        {
                            x = buttonScreen.WorkingArea.Right - _contextMenuStrip.Bounds.Width;
                        }
                        if( y + _contextMenuStrip.Bounds.Height > buttonScreen.WorkingArea.Bottom )
                        {
                            y = buttonScreen.WorkingArea.Bottom - _contextMenuStrip.Bounds.Height;
                        }

                        Point display = context.RibbonControl.PointToClient( new Point( x, y ) );

                        _contextMenuStrip.Show( context.RibbonControl, display );

                        return true;
                    }
                }
            }

            return base.OnClick( context );
        }
        protected override bool OnClick( Context context )
        {
            if( _contextMenuStrip != null )
            {
                SuperToolTipManager.CloseToolTip();

                Rectangle itemBounds = context.GetItemBounds( this );

                if( CommandControlSet != null )
                {
                    CommandControlSet.UpdateState();
                }

                Point buttonPosn = this.Section.Ribbon.PointToScreen( itemBounds.Location );
                Rectangle buttonRect = new Rectangle( buttonPosn, itemBounds.Size );
                Point screen = WinFormsUtility.Controls.ControlUtils.FixForScreen( buttonRect );

                Point display = context.RibbonControl.PointToClient( screen );

                _contextMenuStrip.Show( context.RibbonControl, display );

                return true;
            }
            else
            {
                return false;
            }
        }
Exemple #3
0
            protected override bool OnClick( Context context )
            {
                ContextMenuStrip contextMenu = new ContextMenuStrip();
                Section lastSection = null;

                foreach( Section section in context.RibbonControl.Sections )
                {
                    if( context.RibbonControl.LevelOfDetail <= section.DisplayUntil )
                    {
                        continue;
                    }

                    foreach( Item item in section.Items )
                    {
                        System.Windows.Forms.ToolStripItem menuItem = item.CreateEquivalentToolStripItem();

                        if( menuItem != null )
                        {
                            if( lastSection != null && lastSection != section )
                            {
                                contextMenu.Items.Add( new ToolStripSeparator() );
                            }

                            contextMenu.Items.Add( menuItem );
                            lastSection = section;
                        }
                    }
                }

                Rectangle itemRect = context.GetItemBounds( this );

                contextMenu.Show( context.RibbonControl, new Point( itemRect.X, itemRect.Bottom ) );

                return true;
            }