C
ChJK
Unregistered / Unconfirmed
GUEST, unregistred user!
在盒子的相同问题网址:http://bbs.2ccc.com/topic.asp?topicid=290593
如何做像MSN8.5版的列表树结构,我找到一个在ListView画进度条的源代码,网址如下:http://blog.csdn.net/xzhifei/archive/2007/02/26/1515074.aspx
我针TreeView对做了修改但效果不太好,主要几个问题就是TreeView的每一节点的高度没有MSN的高(TreeView的高度是16),再有就是节点图标不能透明显示等等一些问题,TreeView的CustomDrawItem事件如下:
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode;
State: TCustomDrawState;
var DefaultDraw: Boolean);
var
BoundRect, Rect: TRect;
i,wt: integer;
TextFormat: Word;
TV: TTreeView;
procedure Draw_ImageList(r: TRect;
aCanvas: TCanvas;
Checked: Boolean);
var
R1: TRect;
i: integer;
begin
i:=Node.ImageIndex;
if i > -1 then
begin
//获取图标的RECT
R1.Top:=r.Top;
R1.Left:=r.Left;
R1.Right:=16;
R1.Bottom:=16;
if (Node.HasChildren) or Node.Expanded then
begin
wt:= 0;
end
else
wt:=16;
if Rect.Right >R1.Right then
TV.Images.Draw(TV.Canvas, R1.Left+wt, R1.Top, i);
end;
end;
begin
TV := TreeView1;
BoundRect := Node.DisplayRect(False);
InflateRect(BoundRect, -1, 0);
//这个地方你可以根据自己的要求设置成想要的颜色,实现突出显示
TV.Canvas.Font.Color := clBtnText;
//查看是否是被选中
if Node.Selected then
begin
if cdsFocused in State then
begin
TV.Canvas.Brush.Color := $00ECCCB9;
// //clHighlight;
end
else
begin
TV.Canvas.Brush.Color := $00F8ECE5;
//clSilver;
end;
end
else
TV.Canvas.Brush.Color := clWhite;
TV.Canvas.FillRect(BoundRect);
//初始化背景
TextFormat := 0;
Rect:= Node.DisplayRect(false);
//先画图标
Draw_ImageList(Rect, TV.Canvas, False);
//再画Caption的文字
if (Node.HasChildren) or Node.Expanded then
begin
wt:= 0;
end
else
wt:=16;
if (Rect.Right - Rect.Left)>=TV.StateImages.Width then
begin
InflateRect(Rect, -(5 +wt+16), 0);
//向后移3个像素,避免被后面画线框时覆盖
DrawText(
TV.Canvas.Handle,
PCHAR(Node.Text),
Length(Node.Text),
Rect,
DT_VCENTER or DT_SINGLELINE or DT_END_ELLIPSIS or TextFormat);
end;
TV.Canvas.Brush.Color := clWhite;
if Node.Selected then
//画选中条外框
begin
if cdsFocused in State then
//控件是否处于激活状态
TV.Canvas.Brush.Color := $00DAA07A
else
TV.Canvas.Brush.Color := $00E2B598;
TV.Canvas.FrameRect(BoundRect);
//
end;
DefaultDraw := False;
//不让系统画了
with Sender.Canvasdo
if Assigned(Font.OnChange) then
Font.OnChange(Font);
end;
望高手大哥指点!
如何做像MSN8.5版的列表树结构,我找到一个在ListView画进度条的源代码,网址如下:http://blog.csdn.net/xzhifei/archive/2007/02/26/1515074.aspx
我针TreeView对做了修改但效果不太好,主要几个问题就是TreeView的每一节点的高度没有MSN的高(TreeView的高度是16),再有就是节点图标不能透明显示等等一些问题,TreeView的CustomDrawItem事件如下:
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode;
State: TCustomDrawState;
var DefaultDraw: Boolean);
var
BoundRect, Rect: TRect;
i,wt: integer;
TextFormat: Word;
TV: TTreeView;
procedure Draw_ImageList(r: TRect;
aCanvas: TCanvas;
Checked: Boolean);
var
R1: TRect;
i: integer;
begin
i:=Node.ImageIndex;
if i > -1 then
begin
//获取图标的RECT
R1.Top:=r.Top;
R1.Left:=r.Left;
R1.Right:=16;
R1.Bottom:=16;
if (Node.HasChildren) or Node.Expanded then
begin
wt:= 0;
end
else
wt:=16;
if Rect.Right >R1.Right then
TV.Images.Draw(TV.Canvas, R1.Left+wt, R1.Top, i);
end;
end;
begin
TV := TreeView1;
BoundRect := Node.DisplayRect(False);
InflateRect(BoundRect, -1, 0);
//这个地方你可以根据自己的要求设置成想要的颜色,实现突出显示
TV.Canvas.Font.Color := clBtnText;
//查看是否是被选中
if Node.Selected then
begin
if cdsFocused in State then
begin
TV.Canvas.Brush.Color := $00ECCCB9;
// //clHighlight;
end
else
begin
TV.Canvas.Brush.Color := $00F8ECE5;
//clSilver;
end;
end
else
TV.Canvas.Brush.Color := clWhite;
TV.Canvas.FillRect(BoundRect);
//初始化背景
TextFormat := 0;
Rect:= Node.DisplayRect(false);
//先画图标
Draw_ImageList(Rect, TV.Canvas, False);
//再画Caption的文字
if (Node.HasChildren) or Node.Expanded then
begin
wt:= 0;
end
else
wt:=16;
if (Rect.Right - Rect.Left)>=TV.StateImages.Width then
begin
InflateRect(Rect, -(5 +wt+16), 0);
//向后移3个像素,避免被后面画线框时覆盖
DrawText(
TV.Canvas.Handle,
PCHAR(Node.Text),
Length(Node.Text),
Rect,
DT_VCENTER or DT_SINGLELINE or DT_END_ELLIPSIS or TextFormat);
end;
TV.Canvas.Brush.Color := clWhite;
if Node.Selected then
//画选中条外框
begin
if cdsFocused in State then
//控件是否处于激活状态
TV.Canvas.Brush.Color := $00DAA07A
else
TV.Canvas.Brush.Color := $00E2B598;
TV.Canvas.FrameRect(BoundRect);
//
end;
DefaultDraw := False;
//不让系统画了
with Sender.Canvasdo
if Assigned(Font.OnChange) then
Font.OnChange(Font);
end;
望高手大哥指点!