> Is there a trick to display multline tooltips?
>
> In my Treeview, I have ToolTips checked, and in the OnHint event
> handler I set my hint, separating each part of the hint with #13#10.
> However only the first line is displayed.
after the first line break. To display multi-line text, you need to manually
set the tooltip window to allow multiple lines, then it will respect your
line breaks. To do that, subclass the TTreeView to intercept the TTN_NEEDTEXT
notification and send a TTM_SETMAXTIPWIDTH message directly to the tooltip
window to specify a maximum width for text wrapping (the default is -1, meaning
no max width), which also activates line break handling.
I tried the following in Delphi XE2 and it worked for me. You can adjust
the desired maximum width as desired:
{code:delphi}
type
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure TreeView1Hint(Sender: TObject; const Node: TTreeNode;
var Hint: string);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
DefTreeViewWndProc: TWndMethod;
procedure TreeViewWndProc(var Message: TMessage);
public
{ Public declarations }
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DefTreeViewWndProc := TreeView1.WindowProc;
TreeView1.WindowProc := TreeViewWndProc;
end;
procedure TForm1.TreeView1Hint(Sender: TObject; const Node: TTreeNode;
var Hint: string);
begin
Hint := 'Test'#13#10 + Node.Text;
end;
procedure TForm1.TreeViewWndProc(var Message: TMessage);
var
MaxWidth: Integer;
begin
if Message.Msg = WM_NOTIFY then
begin
with TWMNotify(Message).Nmhdr^ do
begin
if code = TTN_NEEDTEXTW then
begin
MaxWidth := SendMessage(hwndFrom, TTM_GETMAXTIPWIDTH, 0, 0);
if MaxWidth = -1 then
SendMessage(hwndFrom, TTM_SETMAXTIPWIDTH, 100, 0);
end;
end;
end;
DefTreeViewWndProc(Message);
end;
{code}
--
Remy Lebeau (TeamB)