5

I'm trying to find a way to use my 2nd form as a hint window for a component (for example a TLabel) in my 1st form.

At the moment, I'm exploring the use of THintWindow and HintWindowClass, but it is not possible to directly assign a TForm to HintWindowClass. Some examples I've seen so far use a TBitmap which is then drawn on the THintWindow.Canvas, which is not bad, but I'd still like to use some kind of integrated automatic mechanism.

Another solution that crossed my mind is to manually implement this functionality using OnMouseEnter, OnMouseMove and OnMouseLeave events of the said Tlabel.

If there actually is a way to "assign" a TForm to HintWindowClass, I'd like to ask if anyone can provide a code snippet illustrating this. Thanks.

LightBulb
  • 964
  • 1
  • 11
  • 27
  • http://meta.stackoverflow.com/questions/295049/criteria-for-flagging-an-off-topic-question –  May 22 '15 at 19:50

1 Answers1

12

THintWindow is a descendant of TCustomControl. TForm is not a descendant of either of those classes, so you cannot assign any TForm class to HintWindowClass. Hint windows need to descend from THintWindow. Anything you can put on a form you can also put on a THintWindow. You'll just have to instantiate it manually and assign its Parent property to make it appear.

The closest you can probably get to "visually" designing a hint window is to design a frame. Make your THintWindow descendant create an instance of the frame, and then override ActivateHint (and ActivateHintData, if you need the data) to forward the hint text and desired size to your frame.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • 3
    It's a little bit hacky, but you could place the form you want to use as a hint inside a container derived from `THintWindow`. You would set `Form.Parent := HintWindowContainer; Form.Align := alClient;` – David Heffernan Jan 27 '11 at 15:46
  • I'm not sure on the policy of "reviving" one year old questions here, but this is the exact question that I have right now. I understand what needs to be done, but I don't know how to exactly. I have made `TMyHintWindow` descendant and looked at `ActivateHint` and from there I'm lost, do I completely throw away the original code, where should I put the creation of an instance of a frame? I tried doing it in `ActivateHint`, it gets created but never shows up... then again, I didn't reuse any original code, so that's probably completely wrong. I would appreciate some help with this. – Raith Jun 21 '12 at 22:13