Exemplo n.º 1
0
        public override RibbonItem GetItemFromPoint(Point location)
        {
            RibbonToolStrip targetTool = null;

            foreach (var tool in this.ToolStrips)
            {
                if (GetToolStripBounds(tool).Contains(location))
                {
                    targetTool = tool;
                    break;
                }
            }
            if (targetTool == null)
            {
                return(null);
            }

            foreach (var item in targetTool.ToolItems)
            {
                if (targetTool.GetItemBounds(item).Contains(location))
                {
                    return(item);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public Rectangle GetToolStripBounds(RibbonToolStrip tool)
        {
            Rectangle groupBounds = this.Services.GetBounds(this);
            int       totalHeight = groupBounds.Height - HeaderHeight - 2 * GroupBorder;
            int       totalLines  = this.placedToolStrips.Length;
            int       yPadding    = Math.Max(1, (totalHeight - RibbonToolStrip.ToolStripHeight * totalLines) / (1 + totalLines));

            List <RibbonToolStrip> tools = this.placedToolStrips[tool.LineNumber];
            int index = tools.IndexOf(tool);
            int x     = groupBounds.Left + GroupBorder + (index + 1) * GroupPadding + tools.Take(index).Select(t => t.UpdatedWidth).Sum();
            int y     = groupBounds.Top + GroupBorder + (tool.LineNumber + 1) * yPadding + tool.LineNumber * RibbonToolStrip.ToolStripHeight;
            int w     = tool.UpdatedWidth;
            int h     = RibbonToolStrip.ToolStripHeight;

            return(new Rectangle(x, y, w, h));
        }