TTreeView.OnCustomDrawItem
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的更多相关文章
- 给 TTreeView 添加复选框
//1.引用单元 uses Commctrl ; //2.定义私有过程 procedure tvToggleCheckbox(TreeView: TTreeView;Node: TTreeNode;i ...
- delphi TTreeView组件遍历磁盘目录
TTreeView组件遍历磁盘目录 实例说明 TTreeView组件是一个以分枝结构或者说树状结构显示数据的组件,以该组件显示数据具有较好的等级关系和逻辑层次,并且易于操作.在组件中显示的数据结构与系 ...
- 学习 TTreeView [1] - TTreeNodes、TTreeNode 与 Items、Items.Count、Items.Clear
填写 TTreeView 的内容一般是这样开始的(下图), 不过我觉得最好习惯用动态建立. 打个比方: 譬如 TreeView 是一个军营的"营部"! 这里会有营长.连长.排长.班 ...
- 学习 TTreeView [3] - Add、AddChild、AddFirst、AddChildFirst、Parent
本例效果图: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contro ...
- TTreeView TTreeNodes TTreeNode
TTreeView 填写 TTreeView 的内容一般是这样开始的(下图), 不过我觉得最好习惯用动态建立. 打个比方: 譬如 TreeView 是一个军营的"营部"! 这里会有 ...
- delphi -----TTreeView
TTreeView 与两个重要的类相关:TTreeNodes.TTreeNode . TTreeNodes即是TTreeView 的Items属性,TTreeNodes是TTreeNode的合集,TT ...
- delphi中TTreeView的使用方法
[学习万一老师博客摘要] TTreeView 与两个重要的类相关:TTreeNodes.TTreeNode . TTreeNodes即是TTreeView 的Items属性,TTreeNodes是TT ...
- 学习 TTreeView [2] - Items.Item[i]、Items[i]、.Text、SetFocus(设置焦点)、Select(选择)
本例效果图: 源码: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Co ...
- 学习 TTreeView [16] - 给 TTreeView 添加复选框 (回复 "丁永其" 的问题)
问题来源: http://www.cnblogs.com/del/archive/2008/05/15/1114450.html#1199402 本例效果图: unit Unit1; interfac ...
随机推荐
- stenciljs 学习九 使用jsx
可以使用jsx 方便组件的开发 基本格式 主要是render 函数 class MyComponent { render() { return ( <div> <h1>Hell ...
- 【转】每天一个linux命令(58):telnet命令
原文网址:http://www.cnblogs.com/peida/archive/2013/03/13/2956992.html telnet命令通常用来远程登录.telnet程序是基于TELNET ...
- drbd脑裂问题处理
http://blog.csdn.net/heianemo/article/details/8439813 split brain实际上是指在某种情况下,造成drbd的两个节点断开了连接,都以prim ...
- 转:使用JMeter创建数据库(Mysql)测试
我的环境:MySQL:mysql-essential-5.1.51-win32 jdbc驱动:我已经上传到csdn上一个:http://download.csdn.net/source/3451945 ...
- golang 自定义类型的排序sort
sort包中提供了很多排序算法,对自定义类型进行排序时,只需要实现sort的Interface即可,包括: func Len() int {... } func Swap(i, j int) {... ...
- Python 中的变量
Python采用基于值得内存管理模式,赋值语句的执行过程是:首先把等号右侧标识的表达式计算出来,然后在内存中找一个位置把值存放进去,最后创建变量并指向这个内存地址.Python中的变量并不直接存储值, ...
- g++编译后中文显示乱码解决方案
环境:Windows 10 专业版 GCC版本:5.3.0 测试代码: #include <iostream> using namespace std; int main(int argc ...
- centos7开机界面出现多个选项
第一个选项正常启动,第二个选项急救模式启动(系统出项问题不能正常启动时使用并修复系统) 在CentOS更新后,并不会自动删除旧内核.所以在启动选项中会有多个内核选项,可以手动使用以下命令删除多余的内核 ...
- 关于win时间同步的解决方案
将以下的批处理执行:net stop w32time sc config w32time start= auto net start w32time w32tm /config /update /ma ...
- El中调用静态方法
最近在项目中遇到需要调用静态方法的问题,形如: <c:forEach items="beans" var="bean"> <p>总数:$ ...