How to change TreeView node height, to draw 3 lines in a node

£可爱£侵袭症+ 提交于 2019-12-23 13:04:04

问题


I use D7 with TreeView (not VirtualTreeView). How can I change node height to use OwnerDraw and draw 3 (or 5 or more) "lines" of text in node rectangle?

So tree should look like this (root node + 2 nodes are shown, aaa and bbb):

[+] Root node
 |
 |  [aaa1
 |--[aaa2222
 |  [aaa333
 |
 |  [bbb1
 |--[bbb2222
 |  [bbb333
 |
...

I know how to use owner-draw. But don't know how to make tall node rectangle.


回答1:


The simplest way would be to set the node height when the node is already added in the tree view. This will save you from modifying the original VCL control code. What you need to do is set the iIntegral member of the TVITEMEX structure, which represents multiples of a default node height. If you'd need to set this height in pixels, you'd have to set the default node height by sending TVM_SETITEMHEIGHT message and setting the default node height to 1 pixel, but then the look of the tree view gets broken.

Here is a procedure which sets the node specified by the Node parameter to the height of Integral times of default node height:

procedure SetNodeHeight(Node: TTreeNode; Integral: Integer);
var
  ItemEx: TTVItemEx;
begin
  if not Node.Deleting then
  begin
    ItemEx.mask := TVIF_HANDLE or TVIF_INTEGRAL;
    ItemEx.hItem := Node.ItemId;
    ItemEx.iIntegral := Integral;
    TreeView_SetItem(Node.Handle, ItemEx);
  end;
end;

And the possible usage for setting a node to be 3 times higher than default node height:

procedure TForm1.Button1Click(Sender: TObject);
var
  Node: TTreeNode;
begin
  Node := TreeView1.Items.AddChild(nil, 'Node 3 times higher than default');
  SetNodeHeight(Node, 3);
end;

Surely you can extend the original VCL tree view class with a code like this, but I'll keep this upon you.



来源:https://stackoverflow.com/questions/21001812/how-to-change-treeview-node-height-to-draw-3-lines-in-a-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!