如何获得 TStringGrid 中单元格的提示,使其显示得更流畅?

发布于 2025-01-05 16:32:32 字数 690 浏览 1 评论 0原文

我正在运行 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 技术交流群。

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

发布评论

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

评论(2

叫思念不要吵 2025-01-12 16:32:32

将事件处理程序分配给 TApplication.OnShowHintTApplicationEvents.OnShowHint 事件,或子类化 TStringGrid 以拦截 CM_HINTSHOW > 消息。其中任何一个都可以让您访问用于控制提示窗口行为的 THintInfo 记录。您可以根据需要自定义 THintInfo.CursorRect 成员的坐标。当鼠标移动到该矩形之外时,提示窗口将使用最新的 Hint 属性文本(可以在显示之前使用 THintInfo.HintStr 成员进行自定义)重新激活。矩形越小,重新激活提示窗口的频率就越高。此功能允许 UI 控件在其客户区域内具有多个子部分,当鼠标在同一 UI 控件周围移动时,这些子部分显示不同的提示字符串。

TApplication.HintShortPause 属性的值(或拦截 CM_HINTSHOWPAUSE 消息)控制提示窗口在重新激活之前是否消失。如果将暂停值设置为零,提示窗口会立即更新其文本而不会消失。如果将暂停值设置为非零值,只要鼠标停留在同一 UI 控件上,提示窗口就会消失,然后在经过指定的毫秒数后重新出现。

例如:

procedure TTmMainForm.FormCreate(Sender: TObject);
begin
  Application.OnShowHint := AppShowHint;
end;

procedure TTmMainForm.FormDestroy(Sender: TObject);
begin
  Application.OnShowHint := nil;
end;

procedure TTmMainForm.AppShowHint(var HintStr: String; var CanShow: Boolean; var HintInfo: THintInfo);
var 
  R, C: Integer; 
begin
  if HintInfo.HintControl = SgScoutLink then
  begin
    R := 0; 
    C := 0; 
    SgScoutLink.MouseToCell(HintInfo.CursorPos.X, HintInfo.CursorPos.Y, C, R); 
    if (R = 0) and (C >= 3) and (C <= 20) then 
    begin 
      HintInfo.CursorRect := SgScoutLink.CellRect(C, R);
      HintInfo.HintStr := FManager.ScoutLinkColumnTitles.stGetColumnTitleHint(C-3); 
    end;
  end;
end;

编辑:我刚刚注意到您正在使用 Lazarus。我所描述的是如何在Delphi中处理这个问题。我不知道它是否也适用于拉撒路。

Assign an event handler to the TApplication.OnShowHint or TApplicationEvents.OnShowHint event, or subclass the TStringGrid to intercept the CM_HINTSHOW message. Any one of those will provide you access to a THintInfo record that is used to control the behavior of the hint window. You can customize the coordinates of the THintInfo.CursorRect member as needed. The hint window is reactivated with the latest Hint property text (which can be customized with the THintInfo.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 the CM_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:

procedure TTmMainForm.FormCreate(Sender: TObject);
begin
  Application.OnShowHint := AppShowHint;
end;

procedure TTmMainForm.FormDestroy(Sender: TObject);
begin
  Application.OnShowHint := nil;
end;

procedure TTmMainForm.AppShowHint(var HintStr: String; var CanShow: Boolean; var HintInfo: THintInfo);
var 
  R, C: Integer; 
begin
  if HintInfo.HintControl = SgScoutLink then
  begin
    R := 0; 
    C := 0; 
    SgScoutLink.MouseToCell(HintInfo.CursorPos.X, HintInfo.CursorPos.Y, C, R); 
    if (R = 0) and (C >= 3) and (C <= 20) then 
    begin 
      HintInfo.CursorRect := SgScoutLink.CellRect(C, R);
      HintInfo.HintStr := FManager.ScoutLinkColumnTitles.stGetColumnTitleHint(C-3); 
    end;
  end;
end;

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.

沉溺在你眼里的海 2025-01-12 16:32:32

我找到了以下解决方案...不知道它是否在拉撒路中工作,但我的delphi可以使用它...为网格鼠标移动处理程序编写以下伪代码:

if (current_coords==old_coords) then   
    {showhint=true;hint=use_mousetocell_call_to_create}   
else   
    {showhint=false;hint=''} old_coords=current_coords;

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:

if (current_coords==old_coords) then   
    {showhint=true;hint=use_mousetocell_call_to_create}   
else   
    {showhint=false;hint=''} old_coords=current_coords;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文