HELP - Position tooltip relative to mouse cursor

  • Thread starter Thread starter rino
  • Start date Start date
R

rino

Hi
I want to manually show a tooltip (using Tooltip.Show method) under the
mouse cursor. I have the mouse location but I want to tooltip to be displayed
beneath the mouse. I tried m_tooltip.Show("my text",this,e.X,e.Y +
Cursor.Size.Height)
The problem is the cursor Size returns 32x32 where the actual cursor icon is
smaller so there is a gap and it looks the the tooltip is too far away from
the cursor. How do I get the tooltip to be dispayed right under the actual
cursor icon.

Thanks.
 
Use something like (Cursor.Size.Height \ 2) instead.

Tom Dacon
Dacon Software Consulting
 
Don't know if it's the correct solution, but try subtracting
Cursor.Hotspot.Y from the height (gives the correct result on my system).

m_tooltip.Show("my text",this,e.X,e.Y + Cursor.Size.Height -
Cursor.HotSpot.Y)
 
Hi Tom
Thanks but I think this would be just a guess and not something that can be
relied on .
Thanks.
 
Hi Mick
Thanks , but how did you get to this . from what I read on the hotspot

The hot spot of a cursor is the point to which Windows refers in tracking
the cursor's position. By default, the hot spot is set to the upper-left
corner of the cursor (coordinates 0,0). The Hotspot property in the
Properties window shows the hot spot coordinates.

doesnt look like this would be the proper way

Thanks.
 
Just a guess, saw the same information so am not sure that it's the correct
solution, but it certainly gives me exactly the right results on my system.

The only other way that I can think of to do it (and more likely the way I
would do it), would be to extract the actual bitmap from the cursor and
determine it's size by scanning for rows of transparent pixels.
Will more than likely require Interop, but shouldn't be too difficult.
 
Hi Mick
Thanks. And your suggestion was something I had in mind however.
I was hoping that someone in MS would know the correct answer because I sure
dont want to find myself scaning bitmaps :-)
Anyway I will still give it a wait until I find a more elegant way.
 
I want to manually show a tooltip (using Tooltip.Show method) under the
mouse cursor. I have the mouse location but I want to tooltip to be
displayed
beneath the mouse. I tried m_tooltip.Show("my text",this,e.X,e.Y +
Cursor.Size.Height)
The problem is the cursor Size returns 32x32 where the actual cursor icon
is
smaller so there is a gap and it looks the the tooltip is too far away
from
the cursor. How do I get the tooltip to be dispayed right under the actual
cursor icon.

I'm having deja vu here. Someone just asked about this within, I'd say, the
last three weeks. Let me find the thread (may have been in another
group)....

Oh, it was you. A month ago. In .controls.
 
Thanks. And your suggestion was something I had in mind however.
I was hoping that someone in MS would know the correct answer because I
sure
dont want to find myself scaning bitmaps :-)
Anyway I will still give it a wait until I find a more elegant way.

I think you're going to be waiting a long time. The "correct answer" you're
looking for is most likely the one you've been given. Twice.

The Windows cursor structure does not include any information about the
"used area" of the bitmap. You have to figure it out for yourself.
 
Hi Jeff
for your first remark , I see more than one application that knows exactly
how to position the tooltip and I doubt very very much that they scan the
bitmap and I was hoping by now someone from MS would do the favor of
answering.

Regarding posting the question in 2 different groups ,,, I assumed that it
simply increases the chances of getting an answer but if there is a better
way to do it I sure will make a note of it the next time. Thanks for the
correction.

Thanks.
 
Regarding posting the question in 2 different groups ,,, I assumed that it
simply increases the chances of getting an answer but if there is a better
way to do it I sure will make a note of it the next time. Thanks for the
correction.

If I have already made a post in one group and then I realize I should have
crossposted to another group, I usually reply to my first post and add the
new group to it. Then they're "linked." There are other ways, like simply
making a new posts using both groups, but that's how I do it.
 
for your first remark , I see more than one application that knows exactly
how to position the tooltip and I doubt very very much that they scan the
bitmap and I was hoping by now someone from MS would do the favor of
answering.

I took a look at all the API functions and structures related to cursors and
icons (cursors are just glorified icons, after all). I saw absolutely
nothing that gives you the info you're looking for.

Good luck....
 
rino said:
Hi Tom
Thanks but I think this would be just a guess and not something that can
be
relied on .
Thanks.

Yes, it's a guess, but it's based on inspection of common cursor files and
is refined below.

A cursor is 32x32 pixels, but as you've observed the visible portion of the
cursor doesn't necessarily take up the whole thing, nor is the hot spot
necessarily in the upper-left corner. Visual inspection of common arrow
cursor files in Visual Studio shows that they tend to use a little more than
half the height of the 32x32 square, perhaps 18 pixels or so, with the hot
spot in the upper-left corner.

So without parsing the bitwise contents of the current cursor file - however
you would do that, and I certainly don't know, but I'd try to find a way to
get it as a Cursor object and inspect its properties - your best bet would
be to make an educated guess using instead of my (height / 2) guess
something like (height * 5/8) or (height * 3/4).

If a user has selected a larger-than-usual cursor, perhaps for readability
purposes, the tooltip might overlap the visible cursor image. But for the
average user your guess would work out just fine. And for the relative few
who might be using a larger cursor, what's the worst thing that happens? The
tooltip covers the lower right corner of the arrow. Not a show-stopper, in
my opinion.

For me, this would be one of those "don't let perfect chase away good"
decisions.

You refer to other applications that seem to make the adjustment correctly.
I suggest that you change your screen cursor to a larger one and try the
applications in that environment to see if they adapt to the larger cursor
size. My bet is that they use a guess somewhat like I describe above, and
the tooltip will overlap the larger cursor. But if not, more power to them.

Tom Dacon
Dacon Software Consulting
 
Back
Top