Delphi:如何制作自己的提示窗口?

发布于 2024-09-15 12:55:46 字数 951 浏览 2 评论 0 原文

D6 教授

我们有一个带有特殊网格的特殊应用。它有一个 HintWindow,可以显示无法放置在单元格中的其他信息。例如长备忘录。 当您将鼠标移动到某个单元格时,它会等待 2 秒,并显示信息。

该主题的问题是 HintWindow 无法正常工作,或者与正常的“提示”工作方式相同。

正常提示会出现,但在以下情况下会消失: - 显示时间已过的提示 - 活动形式已停用 - 显示新表格 - 应用程序被另一个任务替换(ALT + TAB)

但是我们的提示窗口无法检测到新表单的显示或应用程序的更改 - 它保留在顶部,直到消失。 time... :-(

我们使用“MouseMove”来检测鼠标变化的另一个问题 - 启动提示。

如果 HintWindow 消失,也会发生此事件。所以我需要使用此代码防止循环显示:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
    Caption := INtTOStr(X) + ' ' + IntToStr(Y) + ' ' + IntToStr(GetTickCount);
    // If same coordinate I don't show it again
    if (LX <> X) or (LY <> Y) then begin
        miHint.DoActivateHint(Self, 'Anytext', 2000, 2000);
        LX := X; LY := Y;
    end;
end;

没有此代码LX、LY HintWindow 循环出现和消失

因此:我们需要知道如何制作一个与应用程序“Hint”相同的方法工作的 HintWindow,但仅限于该网格。 它必须围绕“任务变化”、“形式变化”。怎么做呢?

感谢您的帮助: DD

D6 Prof.

We have a special application with a special grid. It have a HintWindow what can show other informations that cannot place in cells. For example long memos.
When you move the mouse to a cell, it is waiting for 2 sec, and show the informations.

The problem of this theme that HintWindow is not working properly, or in same way that normal "Hints" do.

Normal hints are appearing, and they are disappearing in these cases:
- the hint showing time ellapsed
- the the active form is deactivated
- a new form shown
- application replaced by another task (ALT + TAB)

But our HintWindow is cannot detect that new form showing, or application changed - it is remaining on the top, while until disapp. time... :-(

Another problem that we used "MouseMove" to detect the mouse changing - to start the Hint.

This event is happens also if the HintWindow disappears. So I need to protect against cyclic show with this code:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
    Caption := INtTOStr(X) + ' ' + IntToStr(Y) + ' ' + IntToStr(GetTickCount);
    // If same coordinate I don't show it again
    if (LX <> X) or (LY <> Y) then begin
        miHint.DoActivateHint(Self, 'Anytext', 2000, 2000);
        LX := X; LY := Y;
    end;
end;

Without this LX, LY the HintWindow cyclically appears and dissappears.

So: we need to know how we make a HintWindow that is working in same method like application "Hint", but limited into this grid.
It must close on "task change", "form change". How to do it?

THanks for your help:
dd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

鼻尖触碰 2024-09-22 12:55:46

您最好使用提供的在整个应用程序中显示提示的机制,方法是替换 HintWindowClassHintInfo 参数传递给应用程序的 OnShowHint 事件。也许您可能会在下面找到一些有用的实现细节。

旧答案:
在一个较旧的应用程序中,我为列表框和网格设置了不同的提示类。行为有点分散,但基本上可以归结为:

应用程序中的所有 DBGrid 都分配有一些标识提示,例如:“MyDBGridHint”。应用程序的 OnShowHint 事件测试传递的“HintInfo”的“HintControl”是否是“TCustomDBGrid”,如果是,则调用传递“HintInfo”的过程。

此过程通过使用 Grid 的 MouseCoord 方法和 HintInfo.CursorPos 来查找提示所在的单元格,通过临时更改 Grid 的 DataLink 来获取单元格的显示文本。然后,该过程创建一个 TCanvas 并将其句柄分配给为 Grid 检索的 DC,将网格的字体分配给 Canvas 并测试网格单元的边界是否足以显示文本。如果决定显示提示,则将单元格文本分配给 HintInfo.HintStr,并将派生的提示窗口类分配给 HintInfo.HintWindowClass,计算位置、边界、设置字体等......并返回。

然后 OnShowHint 事件测试以查看 HintStr 是否仍然是网格提示标识符(我在代码中有一条注释“网格拥有的控件会产生此内容。”),如果是,则取消提示。

我不确定尝试这样描述它是否有任何帮助,但这里正在尝试......

You'd better use the provided mechanism that show hints throughout the application, by replacing the HintWindowClass of the HintInfo parameter passed to the Application's OnShowHint event whenever you need to show a customized hint. Maybe you might find some useful implementation details below.

Old Answer:
In one older application I had a different hint class for list boxes and grids. The behavior is a bit scattered but basically it boiled down to;

All DBGrids in the Application is assigned some identifying hint, like: 'MyDBGridHint'. Application's OnShowHint event tests if passed 'HintInfo's 'HintControl' is a 'TCustomDBGrid', and if so calls a procedure passing the 'HintInfo'.

This procedure finds the cell the hint should be on by using Grid's MouseCoord method with HintInfo.CursorPos, gets the display text of the cell by temporarily changing Grid's DataLink. The procedure then creates a TCanvas and assigns its Handle a DC retrieved for the Grid, assigns the font of the grid to the Canvas and tests to see if the grid cell's boundary is sufficient to display the text. If it decides that the hint will be shown, assigns the cell text to HintInfo.HintStr and a derived hint window class to HintInfo.HintWindowClass, calculates the position, boundary, sets the font etc.. and returns.

Then OnShowHint event tests to see if HintStr is still the grid hint identifier (I have a comment in the code with "Owned controls by grids produce this."), and if so cancels the hint.

I'm not sure if trying to describe it like this can be of any help, but here is trying...

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