50分求树控件的使用,万分感谢! ( 积分: 50 )

  • 主题发起人 主题发起人 zpselect
  • 开始时间 开始时间
欢迎高手们大力参予!
 
高手们哪!!!!!!
 
Delphi本身有个例子是可能做得到1、3点
X:/Program Files/Borland/Delphi6/Demos/CustomDraw/customdraw.dpr
 
啊......哈哈,看了那个demo 也是自己画按钮和线的,就是这个函数
你把他加到textout前面调用就OK了,虽然样子难看了点.....-_-

procedure TCustomDrawForm.DrawButton(ARect: TRect; Node: TTreeNode);
var
cx, cy: Integer;
begin
cx := ARect.Left + TV.Indent div 2;
cy := ARect.Top + (ARect.Bottom - ARect.Top) div 2;
with TV.Canvas do
begin
Pen.Color := ButtonColorDialog.Color;
//draw horizontal line.
if Node.HasChildren then
begin
PenPos := Point(cx+FButtonSize, cy);
LineTo(ARect.Left + TV.Indent + FButtonSize, cy);
end else
begin
PenPos := Point(cx, cy);
LineTo(ARect.Left + TV.Indent + FButtonSize, cy);
end;

//draw half vertical line, top portion.
PenPos := Point(cx, cy);
LineTo(cx, ARect.Top-1);

if ((Node.GetNextVisible <> nil) and (Node.GetNextVisible.Level = Node.Level))
or (Node.GetNextSibling <> nil) then
//draw bottom portion of half vertical line.
begin
PenPos := Point(cx, cy);
LineTo(cx, ARect.Bottom+1);
end;

if Node.HasChildren then
begin
//Let's try a circular button instead
Ellipse(cx-FButtonSize, cy-FButtonSize, cx+FButtonSize, cy+FButtonSize);

//draw the horizontal indicator.
PenPos := Point(cx-FButtonSize+2, cy);
LineTo(cx+FButtonSize-2, cy);
//draw the vertical indicator if the node is collapsed
if not Node.Expanded then
begin
PenPos := Point(cx, cy-FButtonSize+2);
LineTo(cx, cy+FButtonSize-2);
end;
end;
//now connect vertical lines of higher level nodes.
Node := Node.Parent;
while Node <> nil do
begin
cx := cx - TV.Indent;
if Node.GetNextSibling <> nil then
begin
PenPos := Point(cx, ARect.Top);
LineTo(cx, ARect.Bottom);
end;
Node := Node.Parent;
end;
end;
end;
 
我试一试
 
语法通不过!
 
。。。。。。这不是个单独的过程嘛.....你写到别处,在treeview事件里调用啊
 
ARect: TRect,这个参数取TreeView的什么值啊
 
-_-你看看那个demo不就知道了?

var
noderect:=trect;
begin
NodeRect := Node.DisplayRect(True);
NodeRect.Left := NodeRect.Left + (Node.Level * TV.Indent);
DrawButton(NodeRect, Node);
end;
 
晚上我试一下!
 
我做出来了!

procedure TMainForm.TVCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
noderect: Trect;
cx, cy: Integer;
begin
NodeRect := Node.DisplayRect(True);
NodeRect.Left := NodeRect.Left + (Node.Level * TV.Indent);
cx := noderect.Left + TV.Indent div 2;
cy := noderect.Top + (noderect.Bottom - noderect.Top) div 2;
with TV.Canvas do
begin
if not Node.HasChildren then
PenPos := Point(cx, cy);
PenPos := Point(cx, cy);
LineTo(cx, noderect.Top - 1);

if ((Node.GetNextVisible <> nil) and (Node.GetNextVisible.Level = Node.Level))
or (Node.GetNextSibling <> nil) then
begin
PenPos := Point(cx, cy);
LineTo(cx, noderect.Bottom + 1);
end;
Node := Node.Parent;
while Node <> nil do
begin
cx := cx - TV.Indent;
if Node.GetNextSibling <> nil then
begin
PenPos := Point(cx, noderect.Top);
LineTo(cx, noderect.Bottom);
end;
Node := Node.Parent;
end;
end;
end;
 
多人接受答案了。
 
后退
顶部