创建自定义提示窗口

发布于 2024-10-14 17:53:47 字数 474 浏览 4 评论 0原文

我正在尝试找到一种方法来使用我的第二个表单作为我的第一个表单中的组件(例如 TLabel)的提示窗口。

目前,我正在探索 THintWindowHintWindowClass 的使用,但无法直接将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小瓶盖 2024-10-21 17:53:47

THintWindowTCustomControl 的后代。 TForm 不是这两个类的后代,因此您不能将任何 TForm 类分配给 HintWindowClass。提示窗口需要从THintWindow下降。任何可以放在表单上的内容也可以放在 THintWindow 上。您只需手动实例化它并分配其 Parent 属性即可使其显示。

最接近“视觉”设计提示窗口的方法是设计一个框架。让您的 THintWindow 后代创建框架的实例,然后覆盖 ActivateHint (和 ActivateHintData,如果您需要数据)以转发提示文本和所需的尺寸到您的框架。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文