TTreeNode *node;
node = this->TreeView1->Items->Add(, "AAAA");
TreeView1->Items->AddChild(node, "aaa1");
TreeView1->Items->AddChild(node, "aaa2");
TreeView1->Items->AddChild(node, "aaa3"); node = this->TreeView1->Items->Add(, "BBBB");
TreeView1->Items->AddChild(node, "aaa1");
TreeView1->Items->AddChild(node, "aaa2");
TreeView1->Items->AddChild(node, "aaa3");

循环插入节点

    TTreeNode *anode;
for (int i = ; i < ; i++)
{
anode = this->TreeView1->Items->Add(, "Node" + String(i));
TreeView1->Items->AddChild(anode, "aaa1");
TreeView1->Items->AddChild(anode, "aaa2");
TreeView1->Items->AddChild(anode, "aaa3");
}

c++

/*
The following example shows how the OnCustomDrawItem event
handler draws items and lines of the tree view after the
OnCustomDraw event handler has filled in the background.
*/

void __fastcall TCustomDrawForm::TVCustomDrawItem(TCustomTreeView *Sender,
TTreeNode *Node, TCustomDrawState State, bool &DefaultDraw)
{
TRect NodeRect;
/*
If DefaultDraw it is true, any of the node's font
properties can be changed. Note also that when
DefaultDraw = True, Windows draws the buttons and
ignores our font background colors, using instead the
TreeView's Color property.
*/

if (State.Contains(cdsSelected))
{
TV->Canvas->Font->Assign(SelectedFontDialog->Font);
TV->Canvas->Brush->Color = SelBkgColorDialog->Color;
}; DefaultDraw = FDefaultDrawItem;
/*
DefaultDraw = False means you have to handle all the
item drawing yourself, including the buttons, lines,
images, and text.
*/

if (!DefaultDraw)
{
//draw the selection rect.
if (State.Contains(cdsSelected))
{
NodeRect = Node->DisplayRect(True);
TV->Canvas->FillRect(NodeRect);
};
NodeRect = Node->DisplayRect(False); if (None1->Checked)
//no bitmap, so paint in the background color.
{
TV->Canvas->Brush->Color = BkgColorDialog->Color;
TV->Canvas->Brush->Style = FBrushStyle;
TV->Canvas->FillRect(NodeRect);
}
else
//don't paint over the background bitmap.
TV->Canvas->Brush->Style = bsClear; NodeRect.Left = NodeRect.Left + (Node->Level * TV->Indent);
// NodeRect.Left now represents the left-most portion
// of the expand button
DrawButton(&NodeRect, Node); // See the CustomDraw demo NodeRect.Left = NodeRect.Left + TV->Indent + FButtonSize;
//NodeRect->Left is now the leftmost portion of the image.
DrawImage(&NodeRect, Node->ImageIndex); // See the CustomDraw demo NodeRect.Left = NodeRect.Left + ImageList->Width;
//Now we are finally in a position to draw the text. TV->Canvas->TextOut(NodeRect.Left, NodeRect.Top, Node->Text);
};
} delphi
{
The following example shows how the OnCustomDrawItem event
handler draws items and lines of the tree view after the
OnCustomDraw event handler has filled in the background.
}

procedure TCustomDrawForm.TVCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
State: TCustomDrawState; var DefaultDraw: Boolean);
var
NodeRect: TRect;
begin
with TV.Canvas do
begin
{
If DefaultDraw it is true, any of the node's font
properties can be changed. Note also that when
DefaultDraw = True, Windows draws the buttons and
ignores our font background colors, using instead the
TreeView's Color property.
}

if cdsSelected in State then
begin
Font.Assign(SelectedFontDialog.Font);
Brush.Color := SelBkgColorDialog.Color;
end; DefaultDraw := False; // FDefaultDrawItem;
{
DefaultDraw = False means you have to handle all the
item drawing yourself, including the buttons, lines,
images, and text.
}

if not DefaultDraw then
begin
//draw the selection rect.
if cdsSelected in State then
begin
NodeRect := Node.DisplayRect(True);
FillRect(NodeRect);
end;
NodeRect := Node.DisplayRect(False); if None1.Checked then
//no bitmap, so paint in the background color.
begin
Brush.Color := BkgColorDialog.Color;
Brush.Style := FBrushStyle;
FillRect(NodeRect)
end
else
//don't paint over the background bitmap.
Brush.Style := bsClear; NodeRect.Left := NodeRect.Left + (Node.Level * TV.Indent);
// NodeRect.Left now represents the left-most portion
// of the expand button
DrawButton(NodeRect, Node); // See the CustomDraw demo NodeRect.Left := NodeRect.Left + TV.Indent + FButtonSize;
//NodeRect.Left is now the leftmost portion of the image.
DrawImage(NodeRect, Node.ImageIndex); // See the CustomDraw demo NodeRect.Left := NodeRect.Left + ImageList.Width;
//Now we are finally in a position to draw the text. TextOut(NodeRect.Left, NodeRect.Top, Node.Text);
end;
end;
end;
												

TTreeView.OnCustomDrawItem的更多相关文章

  1. 给 TTreeView 添加复选框

    //1.引用单元 uses Commctrl ; //2.定义私有过程 procedure tvToggleCheckbox(TreeView: TTreeView;Node: TTreeNode;i ...

  2. delphi TTreeView组件遍历磁盘目录

    TTreeView组件遍历磁盘目录 实例说明 TTreeView组件是一个以分枝结构或者说树状结构显示数据的组件,以该组件显示数据具有较好的等级关系和逻辑层次,并且易于操作.在组件中显示的数据结构与系 ...

  3. 学习 TTreeView [1] - TTreeNodes、TTreeNode 与 Items、Items.Count、Items.Clear

    填写 TTreeView 的内容一般是这样开始的(下图), 不过我觉得最好习惯用动态建立. 打个比方: 譬如 TreeView 是一个军营的"营部"! 这里会有营长.连长.排长.班 ...

  4. 学习 TTreeView [3] - Add、AddChild、AddFirst、AddChildFirst、Parent

    本例效果图: unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Contro ...

  5. TTreeView TTreeNodes TTreeNode

    TTreeView 填写 TTreeView 的内容一般是这样开始的(下图), 不过我觉得最好习惯用动态建立. 打个比方: 譬如 TreeView 是一个军营的"营部"! 这里会有 ...

  6. delphi -----TTreeView

    TTreeView 与两个重要的类相关:TTreeNodes.TTreeNode . TTreeNodes即是TTreeView 的Items属性,TTreeNodes是TTreeNode的合集,TT ...

  7. delphi中TTreeView的使用方法

    [学习万一老师博客摘要] TTreeView 与两个重要的类相关:TTreeNodes.TTreeNode . TTreeNodes即是TTreeView 的Items属性,TTreeNodes是TT ...

  8. 学习 TTreeView [2] - Items.Item[i]、Items[i]、.Text、SetFocus(设置焦点)、Select(选择)

    本例效果图: 源码: unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Co ...

  9. 学习 TTreeView [16] - 给 TTreeView 添加复选框 (回复 "丁永其" 的问题)

    问题来源: http://www.cnblogs.com/del/archive/2008/05/15/1114450.html#1199402 本例效果图: unit Unit1; interfac ...

随机推荐

  1. python表单验证封装

    在Web程序中往往包含大量的表单验证的工作,如:判断输入是否为空,是否符合规则. <!DOCTYPE html><html><head lang="en&quo ...

  2. oracle归档日志配置查询

    归档日志(Archive Log)是非活动的重做日志备份.通过使用归档日志,可以保留所有重做历史记录,当数据库处于ARCHIVELOG模式并进行日志切换式,后台进程ARCH会将重做日志的内容保存到归档 ...

  3. http报头 Accept 与 Content-Type 的区别

    Accept属于请求头, Content-Type属于实体头. Http报头分为通用报头,请求报头,响应报头和实体报头. 请求方的http报头结构:通用报头|请求报头|实体报头 响应方的http报头结 ...

  4. lamba数据架构以及数据湖

    面试大数据项目,面试过程中发现面试官提到的两个概念没有搞清楚: 1. lamba数据架构:这个概念的提出是由storm的作者提出来的,其实主旨就是想要说明,数据的处理分成三层,一类是批处理程序(bat ...

  5. codevs2189数字三角形(%100)

    题目:http://codevs.cn/problem/2189/ %100的话就加一维状态.把最优性改为可行性(存在性). #include<iostream> #include< ...

  6. Microsoft Dynamics CRM 2011 新建实体 需要注意的细节

    新建一个实体,需要红色框内的是否勾选的意义,可以进一步加深对CRM的理解.如图: 下面对部分的进行了自我的理解,不对的地方,还请大家指出来.互相学习. 1.CRM2011中,在活动方面加强的新特性包括 ...

  7. 【python】网络编程-套接字常用函数

  8. 关于Redis的那些事

    1.  MySql+Memcached架构的问题 Memcached采用客户端-服务器的架构,客户端和服务器端的通讯使用自定义的协议标准,只要满足协议格式要求,客户端Library可以用任何语言实现. ...

  9. zabbix cpu 负载不对的原因

    最近给客户安装了一个zabbix服务器,运行了几天发现cpu load值不准确, 请教了运维和系统工程师,说是zabbix2.0以后的问题.   解决方案如下1(推荐): 修改模板(Template ...

  10. 关于wp数据备份

    差点忘记记录,之前一直用wp数据备份,但是一直发送邮件不成功,后来才发现,原来是因为发送的邮箱没有设置开通那个什么pop鬼的,不记得叫什么了,看下图. 开通这个服务,就可以正常接收wp的数据邮件备份了 ...