Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2334
Add tooltip to EditorButton
posted

 

I would like to add a tooltip to an EditorButton that I added to the UltraDateTimeEditor in the ButtonsRight collection.

 

editor.ButtonsRight.Add(new EditorButton("btnRelative"));

 

How can get a tooltip for just that editor button and not the entire date time editor?

 

Thanks!

Parents
  • 69832
    Verified Answer
    Offline posted

    I was able to hack this out but I couldn't find a way to make the tooltip disappear when the mouse leaves the button. I set the AutoPopDelay to 2 sec. to work around this, so at least it goes away after a certain amount of time. You might want to submit a feature request for a ToolTipText property to be added to the EditorButton class.

    Example:
    EditorButton button = new EditorButton();
    this.textEditor.ButtonsRight.Add( button );
    this.textEditor.CreationFilter = new CreationFilter();

    private class CreationFilter : IUIElementCreationFilter
    {
        void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent)
        {
            ButtonUIElementBase buttonElement = parent as ButtonUIElementBase;
            if ( buttonElement != null )
            {
                ToolTipProviderUIElement tooltipElement = new ToolTipProviderUIElement( buttonElement );
                tooltipElement.Rect = buttonElement.Rect;
                buttonElement.ChildElements.Add( tooltipElement );
            }
        }

        bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent)
        {
            return false;
        }
    }

    private class ToolTipProviderUIElement : UIElement, IToolTipItem
    {
        public ToolTipProviderUIElement(UIElement parent) : base(parent)
        {
            this.ToolTipItem = this;
        }

        protected override void DrawBackColor(ref UIElementDrawParams drawParams){}

        protected override bool WantsInputNotification(UIElementInputType inputType, Point point)
        {
            return inputType == UIElementInputType.MouseHover;
        }

        ToolTipInfo IToolTipItem.GetToolTipInfo(Point mousePosition, UIElement element, UIElement previousToolTipElement, ToolTipInfo toolTipInfoDefault)
        {
            toolTipInfoDefault.AutoPopDelay = 2000;
            toolTipInfoDefault.ToolTipText = "it worked";
            return toolTipInfoDefault;
        }
    }

Reply Children
No Data