Tooltip on scrollbar

This has got to be simple...  500 points for anyone that can help.

I want to show a tooltip on a scrollbar control.  When the user presses the mouse down, and moves the scrollbar, I want a tooltip to show the current value, right where the pointer is on the scrollbar.  When the mouse button is released, the tooltip goes away.  I don't want to see anything when the mouse hovers over the scrollbar.

I know I have to do something on the Scroll event, with Type=Thumb, to show the tooltip.  And when the Scroll event is a Type=EndScroll, do something to remove the tooltip.  The question is: What do I do in the event handler to show and hide the tooltip?
johneandersonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DabasCommented:
John:

I think that your difficulty rises because you are trying to use the standard tooltip in a non standard way.
I suggest you create your own custom control, that looks similar to the tooltip, and then show it (and hide it) at exactly the correct location with the correct value.
This should be an easier approach than trying to get the standard tooltip to work, because you have full control over what is happening

Dabas
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SanclerCommented:
Although Dabas posted whilst I was drafting, I'll still add my contribution, as it puts some (although not all) meat on Dabas' bones.

I don't think you can actually use the ToolTip control for this: at least "out of the box".  That's because it is specifically designed to show with a hover - which you don't want - and to disappear when the mouse-button is pressed - which is what you do want.

But you might be able to get a similar end result with a Label.  In design view put a label directly adjacent to the scrollbar.  To get as close to the appearance of a ToolTip as possible use a color such as LemonChiffon and a FixedSingle border style.  Then in your scroll event sub put code on these lines

        Dim topArrowDepth As Integer = 20
        Dim multiplier As Single = 1.5
        If e.Type = ScrollEventType.ThumbPosition OrElse e.Type = ScrollEventType.ThumbTrack Then
            lbl.Visible = True
            lbl.Top = vsb.Top + topArrowDepth + (vsb.Value + * multiplier)
            lbl.Text = vsb.Value.ToString
        ElseIf e.Type = ScrollEventType.EndScroll Then
            lbl.Visible = False
        End If

That "on these lines" is very important.  That worked _more or less_ OK on a test, but keeping the label _exactly_ in line with the thumb press would require more detailed calculation of the relationship between the .Value and the relative position of the thumb press within the overall dimensions of the scrollbar than I could be bothered with.

So it's definitely an idea, not a finished product ;-)

Roger
0
johneandersonAuthor Commented:
Thank you both for your input.  After doing some further experimentation, I found a solution (with one caveat) that uses the ToolTip after all.  See the code snippet.  VScrollBar instance is vScrollBar, ToolTip instance is toolTip.  It uses a combination of SetToolTip(), Show() and Hide().  Also, I set all the delay properties (xxxDelay) to 0.

The caveat is that the tool tip appears whenever the mouse hovers over the scrollbar, but only after the scrollbar has been moved at least once.  Something I can live with. (500 points to you if you can solve that one).

Don't ask me why the calls to Show() and Hide() in the form Shown event are there.  But without them, the tooltip will not appear the very first time the scrollbar is moved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
 
namespace ScrollBarTester {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
 
        private void vScrollBar_Scroll(object sender, ScrollEventArgs e) {
            if (e.Type == ScrollEventType.EndScroll) {
                toolTip.Hide(vScrollBar);
            }
            else {
                string message = string.Format("New value = {0}", e.NewValue);
                toolTip.SetToolTip(vScrollBar, message);
                toolTip.Show(message, vScrollBar);
            }
        }
 
        private void Form1_Shown(object sender, EventArgs e) {
            toolTip.Show("", vScrollBar);
            toolTip.Hide(vScrollBar);
        }
    }
}

Open in new window

0
johneandersonAuthor Commented:
I have gotten this to work the way I originally wanted, but it was a lot of trial and error.  Thanks for your input.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.