A
A
Andrey Golubkov2015-01-24 08:14:02
Delphi
Andrey Golubkov, 2015-01-24 08:14:02

How can I overlay text on an image so that a tooltip pops up when hovering the mouse?

062a0d1330694a3eab594c1b6c73d791.jpga6329f6703b1494db94a78d208df83e8.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2015-01-24
@Android97

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 question

Ask a Question

731 491 924 answers to any question