Creating custom Hint window
Asked Answered
P

1

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.

Phenacaine answered 27/1, 2011 at 14:58 Comment(0)
C
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.

Cowlick answered 27/1, 2011 at 15:11 Comment(2)
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;Effects
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.Leptophyllous

© 2022 - 2024 — McMap. All rights reserved.