Answer the question
In order to leave comments, you need to log in
How can I overlay text on an image so that a tooltip pops up when hovering the mouse?
Answer the question
In order to leave comments, you need to log in
The task is divided into three questions.
I. How to intercept the mouse? OnMouseMove and OnMouseLeave (I guess so...)
II. How to draw hint? There are three ways to do this, choose any:
1. Print a tooltip on the viewer component (for example, in the OnPaint event). For example, the “rat” was summed up - InvalidateRect, approximately corresponding to the location of the hint (well, or Invalidate as a whole, if you think that the picture is drawn quickly). In OnPaint - the actual rendering.
2. Make your own hint window - for example, the same TForm. Attention, TLabel does not know how to calculate the vertical size when the text is wrapped, so either find a component that closes this miscalculation, or draw the text yourself, as in the first part.
3. Display the tooltip using WinApi.
III. Here we have calculated the dimensions of the hint and we want to place it within the borders of the screen (options 2, 3) or the window (option 1). Where to stick it? Make several arrangements, in order of preference.
• Bottom, left horizontal alignment. If it fits vertically, but crawls out horizontally, move it to the left.
• Then from above with the same conditions.
• Then to the right; vertical alignment - as it fits.
• Then left; vertical alignment - as it fits.
• And if none of the options failed - by coordinates (0, 0).
Oh yes. When calculating dimensions, make sure that very long captions wrap so that there is no tooltip that is wider than the screen.
That's it in general terms. I had to do it; I used the 1st method, however, the “seed” was not a rectangle, but a point (the captions for the graph were needed). Naturally, I aligned with a small indent so that the cursor does not block the signature. I used Graphics32 with my own code for drawing a rounded rectangle, which turned out to be pretty little translucent dice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question