2017-12-18 131 views
0

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

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

回答

2

首先,你必须揭露了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下)的坐标,并将坐标传递给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; 
+1

这很好。我将我的TListView子类命名为“THintPostListView”,并将声明和函数放在单独的基本单元中,以便任何表单可以根据需要使用该控件。在使用控件的表单的顶部,只需声明'TListView = class(THintPosListView);'就像这个例子。 – AlainD

3

可以显示在例如OnInfoTip()事件中定义的提示。 StatusBarStatusPanel(在表格的底部)。

例如:

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

不错,简单的解决方案!尽管如此,还是需要在表单某处显示未使用的空间来显示提示细节。 – AlainD