如何获得 TStringGrid 中单元格的提示,使其显示得更流畅?
我正在运行 Lazarus 0.9.30。
我在表单上有一个标准的 TStringGrid
,并且希望在将鼠标指针移到列标题上时显示不同的提示。我正在使用这段代码来执行此操作,并且它可以工作,但是当我实际上希望它随着鼠标指针在其上移动时进行更改时,您经常必须单击单元格才能获得更改的提示。我将所有提示存储在一个集合中,我使用列索引作为键进行搜索。 有没有办法让提示显示更流畅?
procedure TTmMainForm.SgScoutLinkMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
R, C: Integer;
begin
R := 0;
C := 0;
SgScoutLink.MouseToCell(X, Y, C, R);
with SgScoutLink do
begin
if (R = 0) then
if ((C >= 3) and (C <= 20)) then
begin
SgScoutLink.Hint := FManager.ScoutLinkColumnTitles.stGetColumnTitleHint(C-3);
SgScoutLink.ShowHint:= True;
end; {if}
end; {with}
end;
I am running Lazarus 0.9.30.
I have a standard TStringGrid
on a form and want to show a different hint as I move my mouse pointer over a column title. I am using this code to do this and it sort of works but you often have to click on the cell to get the hint to change, when I actually want it to change as the mouse pointer moves over it. I have all the hints stored in a collection that I search through using the column index as the key.
Is there a way to get more smooth display of hints?
procedure TTmMainForm.SgScoutLinkMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
R, C: Integer;
begin
R := 0;
C := 0;
SgScoutLink.MouseToCell(X, Y, C, R);
with SgScoutLink do
begin
if (R = 0) then
if ((C >= 3) and (C <= 20)) then
begin
SgScoutLink.Hint := FManager.ScoutLinkColumnTitles.stGetColumnTitleHint(C-3);
SgScoutLink.ShowHint:= True;
end; {if}
end; {with}
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将事件处理程序分配给
TApplication.OnShowHint
或TApplicationEvents.OnShowHint
事件,或子类化TStringGrid
以拦截CM_HINTSHOW
> 消息。其中任何一个都可以让您访问用于控制提示窗口行为的THintInfo
记录。您可以根据需要自定义THintInfo.CursorRect
成员的坐标。当鼠标移动到该矩形之外时,提示窗口将使用最新的Hint
属性文本(可以在显示之前使用THintInfo.HintStr
成员进行自定义)重新激活。矩形越小,重新激活提示窗口的频率就越高。此功能允许 UI 控件在其客户区域内具有多个子部分,当鼠标在同一 UI 控件周围移动时,这些子部分显示不同的提示字符串。TApplication.HintShortPause
属性的值(或拦截CM_HINTSHOWPAUSE
消息)控制提示窗口在重新激活之前是否消失。如果将暂停值设置为零,提示窗口会立即更新其文本而不会消失。如果将暂停值设置为非零值,只要鼠标停留在同一 UI 控件上,提示窗口就会消失,然后在经过指定的毫秒数后重新出现。例如:
编辑:我刚刚注意到您正在使用 Lazarus。我所描述的是如何在Delphi中处理这个问题。我不知道它是否也适用于拉撒路。
Assign an event handler to the
TApplication.OnShowHint
orTApplicationEvents.OnShowHint
event, or subclass theTStringGrid
to intercept theCM_HINTSHOW
message. Any one of those will provide you access to aTHintInfo
record that is used to control the behavior of the hint window. You can customize the coordinates of theTHintInfo.CursorRect
member as needed. The hint window is reactivated with the latestHint
property text (which can be customized with theTHintInfo.HintStr
member before it is displayed) whenever the mouse moves outside of that rectangle. The smaller the rectangle, the more often the hint window is reactivated. This feature allows a UI control to have multiple subsections within its client area that display different hint strings while the mouse is moving around that same UI control.The value of the
TApplication.HintShortPause
property (or from intercepting theCM_HINTSHOWPAUSE
message) controls whether the hint window disappears before reactivating. If you set the pause value to zero, the hint window updates its text immediately without disappearing. If you set the pause value to a non-zero value, the hint window disappears and then reappears after the specified number of milliseconds have elapsed, as long as the mouse remains over the same UI control.For example:
Edit: I just noticed that you are using Lazarus. What I described is how to handle this issue in Delphi. I have no clue if it also applies to Lazarus or not.
我找到了以下解决方案...不知道它是否在拉撒路中工作,但我的delphi可以使用它...为网格鼠标移动处理程序编写以下伪代码:
I came to the following solution... have no idea if it works in lazarus but my delphi is ok with it... Write the following pseudo-code for the grid mousemove handler: