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
505
Enabling scrolling with the mouse wheel when the tooltip is displayed, change tooltip font
posted

The default tooltip that is displayed when the node text is truncated (as determined by the Override.TipStyleNode property) prevents the control from being scrolled using the mouse wheel.
The default behaviour is to display this tooltip immediately on mouse enter so there isn't even a grace period where you can get to scroll the tree before the tooltip is displayed.

I have managed to work around this, what we need to do is to get hold of the actual form that is used to display the tooltip, handle it's MouseWheel event and forward it to the tree control instead. The actual tooltip object used to display the tooltip is in fact a member of the UltraTree, it just isn't public. Get hold of this object using reflection, then the form is stored in the Control property on which we register the event. Then in the MouseWheel event we need to call OnMouseWheel on the tree, I'm using reflection again to do this to save me from having to inherit from UltraTree. The code looks like this:

        public Form1()
        {
            InitializeComponent();

            // Get the tooltip using reflection
            var toolTipGet = ultraTree1.GetType().GetProperty("ToolTip", BindingFlags.NonPublic | BindingFlags.Instance);
            ToolTip toolTip = (ToolTip)toolTipGet.GetValue(ultraTree1, null);
            // Control is the form used to display the tooltip and hence gets the mouse events
            toolTip.Control.MouseWheel += Owner_MouseWheel;
        }

        void Owner_MouseWheel(object sender, MouseEventArgs e)
        {
            // forward to the tree
            var omw = ultraTree1.GetType().GetMethod("OnMouseWheel", BindingFlags.NonPublic | BindingFlags.Instance);
            omw.Invoke(ultraTree1, new object[] { e });
        }

I would like Infragistics to build this functionality into the Form the tooltip uses (ToolTipFormEx?).


Also in other forum posts people have asked how to customize the appearance of the tooltip (specifically the font as it defaults to sans serif) and the response has been to roll your own tooltip! There is a much easier way, just set the font on the same protected tooltip object. Note don't set it on the form (tooltip.Control) as some dodgy logic in ToolTip.OnFormDisposed throws an exception when your form is disposed)

            toolTip.Font = ultraTree1.Font;

cheers

    Martin