创建自定义提示窗口
我正在尝试找到一种方法来使用我的第二个表单作为我的第一个表单中的组件(例如 TLabel)的提示窗口。
目前,我正在探索 THintWindow
和 HintWindowClass
的使用,但无法直接将 TForm
分配给 提示窗口类
。到目前为止,我见过的一些示例使用 TBitmap
,然后在 THintWindow.Canvas
上绘制,这还不错,但我仍然想使用某种类型集成自动机构。
我想到的另一个解决方案是使用所述 Tlabel 的 OnMouseEnter 、 OnMouseMove 和 OnMouseLeave 事件手动实现此功能。
如果确实有一种方法可以将TForm
“分配”给HintWindowClass
,我想问是否有人可以提供一个代码片段来说明这一点。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
THintWindow
是TCustomControl
的后代。TForm
不是这两个类的后代,因此您不能将任何TForm
类分配给HintWindowClass
。提示窗口需要从THintWindow
下降。任何可以放在表单上的内容也可以放在THintWindow
上。您只需手动实例化它并分配其Parent
属性即可使其显示。最接近“视觉”设计提示窗口的方法是设计一个框架。让您的
THintWindow
后代创建框架的实例,然后覆盖ActivateHint
(和ActivateHintData
,如果您需要数据)以转发提示文本和所需的尺寸到您的框架。THintWindow
is a descendant ofTCustomControl
.TForm
is not a descendant of either of those classes, so you cannot assign anyTForm
class toHintWindowClass
. Hint windows need to descend fromTHintWindow
. Anything you can put on a form you can also put on aTHintWindow
. You'll just have to instantiate it manually and assign itsParent
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 overrideActivateHint
(andActivateHintData
, if you need the data) to forward the hint text and desired size to your frame.