我的TListView控件启用了ShowHints
并处理OnInfoTip
事件。弹出的InfoTip框中的消息在OnInfoTip
处理程序中设置。但是,弹出窗口信息提示框的位置相对于鼠标悬停在列表中的项目上时的位置。似乎没有办法自定义位置。
是否可以设置提示弹出窗口的位置,例如在TListView的特定区域中,或者甚至在TListView控件边界外的表单上的其他位置?理想情况下,我想以这样的方式显示提示弹出窗口,以最小化(或消除)模糊TListView中的任何其他项目。
首先,您必须公开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;
可以显示您在OnInfoTip()
事件中定义的提示,例如:一个StatusPanel
的StatusBar
(在表格的底部)。
例如:
procedure TForm1.ListView1InfoTip(Sender: TObject; Item: TListItem;
var InfoTip: string);
begin
InfoTip := '';
StatusBar1.Panels[0].Text := 'ListView Infotip, Item '+IntToStr(Item.Index);
end;