Sam Mackrill
Sam Mackrill

Reputation: 4051

How to prevent unwanted tooltip pop-up in Infragistics ComboBoxTool on ribbon control (winforms)

I have a ComboBoxTool on an UltraToolbarsManager implementing a ribbon control. No matter what I set the ToolTipText to it always displays a tooltip:

enter image description here

[e.g. mousing over the gdg combo show this]

I have tried setting all the other tooltip related attributes (ToolTipTextFormatted, ToolTipTitle) to null but this doesn't help.

I have also tried setting-up a very simple ribbon on a dummy project and that does not exhibit this strange behaviour. So it is something else that is effecting this.

Upvotes: 0

Views: 1749

Answers (2)

Sam Mackrill
Sam Mackrill

Reputation: 4051

Infragistics supplied an answer:

  1. Add your own CreationFilter to the ToolbarsManager

    ultraToolbarsManager1.CreationFilter = new MyCreation();

  2. Catch the tool creation and replace the tooltip with your own implementation

    public class MyCreation : IUIElementCreationFilter  {
    
        private readonly int max;
    
        public MyCreation()
        {
        }
    
        public MyCreation(int toolTipMaxWidth)
        {
            max = toolTipMaxWidth;
        }
    
        public void AfterCreateChildElements(UIElement parent)
        {
            parent.ToolTipItem = new MyToolTipItem(max);
        }
    
        public bool BeforeCreateChildElements(UIElement parent)
        {
            return false;
        }
    }
    
    
    public class MyToolTipItem : IToolTipItem   {
        private readonly int max;
    
        public MyToolTipItem(int maxWidth)
        {
            max = maxWidth;
        }
    
        public MyToolTipItem()
        {
        }
    
        public ToolTipInfo GetToolTipInfo(Point mousePosition, UIElement element, UIElement previousToolTipElement,
                                      ToolTipInfo toolTipInfoDefault)
        {
            // set tooltip info for ribbon ApplicationMenuButton
            var app = element as ApplicationMenuButtonUIElement;
            if (app != null)
            {
                var appmenu = ((UltraToolbarsDockAreaUIElement) ((app.Parent).Parent)).ToolbarsManager.Ribbon.ApplicationMenu;
                if (max > 0)
                    toolTipInfoDefault.MaxWidth = max;
                toolTipInfoDefault.Title = appmenu.ToolTipTitle;
    
                string tooltiptex = appmenu.ToolTipText;
                if (!string.IsNullOrEmpty(appmenu.ToolTipTextFormatted))
                {
                    toolTipInfoDefault.ToolTipTextStyle = ToolTipTextStyle.Formatted;
                    tooltiptex = appmenu.ToolTipTextFormatted;
                }
                toolTipInfoDefault.ToolTipText = tooltiptex;
            }
    
            // set tooltip info for tools
            if (element.ToolTipItem != null && UIElement.IsContextOfType(element.GetContext(), typeof (ToolBase)))
            {
                var tool = (ToolBase) element.GetContext(typeof (ToolBase));
                var loc = tool.ToolbarsManager.DockWithinContainer.PointToScreen(new Point(0, 0));
            loc.Offset(tool.UIElement.Rect.Location.X, 185);
    
                if (max > 0)
                    toolTipInfoDefault.MaxWidth = max;
            toolTipInfoDefault.Title = tool.SharedProps.ToolTipTitle;
            string tooltiptex = tool.SharedProps.ToolTipText;
                if (!string.IsNullOrEmpty(tool.SharedProps.ToolTipTextFormatted))
                {
                    toolTipInfoDefault.ToolTipTextStyle = ToolTipTextStyle.Formatted;
                    tooltiptex = tool.SharedProps.ToolTipTextFormatted;
                }
                toolTipInfoDefault.ToolTipText = tooltiptex;
                toolTipInfoDefault.DisplayStyle = Infragistics.Win.ToolTipDisplayStyle.Office2007;
                toolTipInfoDefault.Location = loc;
            }
            return toolTipInfoDefault;
        }
    

Required a bit of tweaking to get the tooltip in the right place and pick-up the tooltip text from TooltipTextResolved.

Upvotes: 1

Mike Dour
Mike Dour

Reputation: 3766

It looks like it may be a bug. You should probably submit it to Infragistics.

If you don't want any tool tips displaying for the entire ribbon group, you can set the RibbonGroup.Settings.ShowToolTips value to False. In fact, if you want to turn off tool tips on a wider scale, you can set one of the following properties to False instead:

  • RibbonTab.GroupSettings.ShowToolTips
  • ContextualTabGroup.GroupSettings.ShowToolTips
  • Ribbon.GroupSettings.ShowToolTips
  • UltraToolbarsManager.ShowToolTips

Each property will turn off tool tips for all tool instances within the associated container.

But if you only want to turn of tool tips for this one tool, you can use a tool that derives from ComboBoxTool. In your derived tool, you can override ShouldDisplayToolTip and you can return False.

Upvotes: 1

Related Questions