设置InfoTip的位置

问题描述 投票:1回答:2

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

是否可以设置提示弹出窗口的位置,例如在TListView的特定区域中,或者甚至在TListView控件边界外的表单上的其他位置?理想情况下,我想以这样的方式显示提示弹出窗口,以最小化(或消除)模糊TListView中的任何其他项目。

windows delphi delphi-7
2个回答
3
投票

首先,您必须公开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的TopLeft Corner的坐标(sbxFilter - 位于TlistView下)并将Coords传递给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;

3
投票

可以显示您在OnInfoTip()事件中定义的提示,例如:一个StatusPanelStatusBar(在表格的底部)。

例如:

procedure TForm1.ListView1InfoTip(Sender: TObject; Item: TListItem;
  var InfoTip: string);
begin
  InfoTip := '';
  StatusBar1.Panels[0].Text := 'ListView Infotip, Item '+IntToStr(Item.Index);
end;
© www.soinside.com 2019 - 2024. All rights reserved.