7

我正在运行 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;
4

2 回答 2

10

将事件处理程序分配给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 中处理这个问题。我不知道它是否也适用于拉撒路。

于 2012-02-15T01:38:39.823 回答
0

我来到了以下解决方案......不知道它是否在 lazarus 中工作,但我的 delphi 没问题......为网格 mousemove 处理程序编写以下伪代码:

if (current_coords==old_coords) then   
    {showhint=true;hint=use_mousetocell_call_to_create}   
else   
    {showhint=false;hint=''} old_coords=current_coords;
于 2015-11-11T01:33:28.037 回答