3

我认为我在自己的 DBGrid 中实现了列标题提示。这似乎很简单——我想。

我添加了

标题提示:TStrings

包含以下格式的信息:

名称=值

其中 name 是 (0-99) 用于非基于字段的列,而 fieldname 用于基于字段的列。value 是该列的 Hint,crlf 是 \n。

一切正常, OnMouseMove 是基于位置的提示。

但是:只显示第一个提示,下一个不显示。我认为这是因为提示机制在鼠标到达“控件”时被激活......当我离开控件并再次出现时,我得到另一个提示 - 一次。无论我将 ShowHint 设置为关闭。

因为如果可能的话我不想创建自己的HintWIndow,所以我寻找一种方法将Hint 机制重置为Applicaion 相信:这是该控件中的第一个案例。我可以以任何方式执行此操作,例如“发送消息”,或者如果存在则调用“取消提示”等。

你知道这种方式吗?

感谢您的帮助,祝您有美好的一天!

问候:dd

4

1 回答 1

3

您可以重新激活您覆盖的提示MouseMove,例如:

type
  TDBGrid = class(DBGrids.TDBGrid)
  private
    FLastHintColumn: Integer;
  protected
    procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
    function GetColumnTitleHint(Col: Integer): string;
    procedure MouseMove(Shift: TShiftState; X: Integer; Y: Integer); override;
  public
    constructor Create(AOwner: TComponent); override;
  end;


procedure TDBGrid.CMHintShow(var Message: TCMHintShow);
var
  Cell: TGridCoord;
begin
  if not Assigned(Message.HintInfo) or not (dgTitles in Options) then
    inherited
  else
  begin
    Cell := MouseCoord(Message.HintInfo^.CursorPos.X, Message.HintInfo^.CursorPos.Y);
    if Cell.Y = 0 then
    begin
      FLastHintColumn := Cell.X - 1;
      Message.HintInfo^.HintStr := GetColumnTitleHint(FLastHintColumn);
    end
    else
      FLastHintColumn := -1;
  end;
end;

function TDBGrid.GetColumnTitleHint(Col: Integer): string;
begin
  Result := Columns[Col].Title.Caption + ' hint';
end;

procedure TDBGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
var
  Cell: TGridCoord;
begin
  inherited MouseMove(Shift, X, Y);
  if dgTitles in Options then
  begin
    Cell := MouseCoord(X, Y);
    if Cell.Y = 0 then
    begin
      if Cell.X - 1 <> FLastHintColumn then
        Application.ActivateHint(Mouse.CursorPos);
    end
    else
      Application.CancelHint;
  end;
end;

constructor TDBGrid.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FLastHintColumn := -1;
end;

GetColumnTitleHint只是一个示例,您应该实现它以从您的TitleHints属性中返回正确的值。

希望这可以帮助。

于 2011-10-14T09:54:23.620 回答