gpt4 book ai didi

delphi - 如何更改树节点矩形大小?

转载 作者:行者123 更新时间:2023-12-03 18:36:15 25 4
gpt4 key购买 nike

我希望我的 TreeView 显示如下。 enter image description here

这是我正在使用的代码。

procedure TForm1.FormShow(Sender: TObject);
begin
TreeView1.FullExpand
end;

procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);

const
_Right = 100;
_Left = 50;

var
R : TRect;

begin

if Node.Level = 0 then
begin

R := Node.DisplayRect(true);

R.Right := R.Right + _Right;
R.Left := R.Left + _Left;

Sender.Canvas.Brush.Color := clRed;
Sender.Canvas.FillRect(R);

end;

end;

问题是我可以扩展 R.right 但不能扩展 R.left ...

最佳答案

如果您在 OnAdvancedCustomDrawItem 中进行绘图事件,还有更多选择。

这对我有用(过滤掉 cdPostPaint 阶段):

procedure TForm1.TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
const
_Right = 100;
_Left = 50;
var
R : TRect;
begin
if (Node.Level = 0) and (stage = cdPostPaint) then
begin

R := Node.DisplayRect(true);
R.Right := R.Right + 2;
Sender.Canvas.FillRect(R); // Just clear default text area

R.Right := R.Right + _Right;
R.Left := R.Left + _Left;
Sender.Canvas.Brush.Color := clRed;
Sender.Canvas.FillRect(R);
{- Make sure writing text with transparent background }
SetBkMode( Sender.Canvas.Handle, TRANSPARENT );
Sender.Canvas.TextOut(R.Left,R.Top,Node.Text);
PaintImages := true;
DefaultDraw := false;
end;
end;

enter image description here

关于delphi - 如何更改树节点矩形大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26098352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com