设置信息提示的位置

Set position of InfoTip

我的 TListView 控件启用了 ShowHints 并处理 OnInfoTip 事件。弹出 InfoTip 框中的消息在 OnInfoTip 处理程序中设置。但是,当悬停在列表中的项目上时,弹出信息提示框的位置是相对于鼠标位置的。似乎没有办法自定义位置。

是否可以设置提示弹出窗口的位置,例如在TListView 的特定区域或什至在TListView 控件边界之外的窗体上的其他地方?理想情况下,我想以这样一种方式显示提示弹出窗口,以尽量减少(或消除)TListView 中任何其他项目的模糊。

可以显示您在 OnInfoTip() 事件中定义的提示,例如a StatusPanel of a StatusBar(在表格底部)。

例如:

procedure TForm1.ListView1InfoTip(Sender: TObject; Item: TListItem;
  var InfoTip: string);
begin
  InfoTip := '';
  StatusBar1.Panels[0].Text := 'ListView Infotip, Item '+IntToStr(Item.Index);
end;

首先你必须暴露TListView的CMHintShow如下:

  type
   TListView = class(Vcl.ComCtrls.TListView)
      private
         FPos: TPoint;
      protected
         procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
      published
         property MyPos: TPoint  read FPos write FPos;
   end;


  TfrmMain = class(TForm)
    ...
    ListView1: TListView;

然后在 OnInfoTip 事件中设置所需的位置。在我的示例中,我获得了 ScrollBox 的左上角坐标(sbxFilter - 位于 TlistView 下)并将坐标传递给 TListView 属性 MyPos.

procedure TfrmMain.ListView1InfoTip(Sender: TObject; Item: TListItem; var InfoTip: string);
var
   p: TPoint;
begin
   InfoTip := 'Test';
   p := sbxFilter.ClientToScreen(point(0, 0));
   ListView1.MyPos := p;
end;


{ TListView }

procedure TListView.CMHintShow(var Message: TCMHintShow);
begin
   inherited;
   Message.HintInfo.HintPos := FPos;
end;