Search code examples
winformstooltipinfragistics

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.

  • If a non-zero length tooltip text is specified then this shows as expected
  • The ribbon child controls are all added programatically
  • The other controls on the ribbon do not have this issue

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.


Solution

  • 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.