如何更改TreeView节点的高度,在一个节点上绘制3条线 [英] How to change TreeView node height, to draw 3 lines in a node
问题描述
我将D7与TreeView(不是VirtualTreeView)一起使用。如何更改节点高度以使用OwnerDraw并在节点矩形中绘制3(或5个或更多)文本行?
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?
所以树应如下所示(根节点+显示2个节点,aaa和bbb):
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.
推荐答案
最简单的方法是在结点处设置结点高度已添加到树视图中。这样可以避免您修改原始的VCL控制代码。您需要做的是设置 TVITEMEX
结构,它表示默认节点高度的倍数。如果需要以像素为单位设置此高度,则必须通过发送 TVM_SETITEMHEIGHT
消息,并将默认节点高度设置为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.
以下是将 Node
参数指定的节点设置为积分
的默认节点高度的倍的高度:
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;
将节点设置为默认节点高度的3倍的可能用法:
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;
当然,您可以使用以下代码扩展原始的VCL树视图类,但我会继续
Surely you can extend the original VCL tree view class with a code like this, but I'll keep this upon you.
这篇关于如何更改TreeView节点的高度,在一个节点上绘制3条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!