TTreeView.OnCustomDrawItem

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

时间: 2024-11-04 22:16:36

TTreeView.OnCustomDrawItem的相关文章

给 TTreeView 添加复选框

1 //1.引用单元 2 uses Commctrl ; 3 4 //2.定义私有过程 5 procedure tvToggleCheckbox(TreeView: TTreeView;Node: TTreeNode;isclick:boolean =false); 6 procedure SetChecked(Node: TTreeNode; Checked: Boolean); 7 function IsChecked(Node: TTreeNode): Boolean; 8 9 //3.过

delphi TTreeView组件遍历磁盘目录

TTreeView组件遍历磁盘目录 实例说明 TTreeView组件是一个以分枝结构或者说树状结构显示数据的组件,以该组件显示数据具有较好的等级关系和逻辑层次,并且易于操作.在组件中显示的数据结构与系统中目录的结构非常相似,所以本例使用该组件设计一个磁盘目录查看工具.运行本例,在窗口右边选择目录或路径就可以在TTreeView组件中列出所有选择目录中的子目录和文件.实例运行效果如图1所示. 图1  TTreeView组件遍历磁盘目录 思路与技术 磁盘中的目录结构就像TTreeView组件中显示的

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

问题来源: http://www.cnblogs.com/del/archive/2008/05/15/1114450.html#1199402 本例效果图: unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, ComCtrls, StdCtrls; type   TForm1 = class(TForm)     Tr

类型TTreeView.items.add 与 TTreeView.items.addchild有何区别?(10分)

我看了书上例子,好象两者都可以实现treeview中的node 的构建. addchild是给当前的node建一个子node,它比当前node要向右缩进几格add建立同级的node,不缩进 aNode :=TreeView1.Items.Add(Node, S)aNode 与 Node 是兄弟.bNode :=TreeView1.Items.AddChild(Node, s);bNode 是 Node 的儿子. TreeView.Item.add增加的是同一级的结点:TreeView.Item.

vcl控件经常使用属性和方法

TTabControl属性 DisplayRect:仅仅定该控件客户区的一个矩形 HotTrack:设置当鼠标经过页标签时,它的字是否有变化.假设为True,是字会变成蓝色Images:为每一个页标签加入一个图片MultiLine:假设总页标签的长度大于该控件的宽度时,是否同意多行显示MultiSelect:是否同意多选页标签.该属性仅仅有当Style为tsFlatButtons或tsButtons时才有效OwnerDraw:是否同意自己绘画该控件RaggedRight:指定是否同意标签页伸展到

取PE文件的引入表和导出表

直接上代码(这里列出C++和Delphi的代码),Delphi代码中包含导入及导出文件和函数列表,PE结构可参阅资料,很多很详细,需要注意的是,本例中是映射到内存,不是通过PE装载器装入的,所以对于节的RVA地址需要转换成为文件偏移地址. Delphi代码 [delphi] view plaincopy unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Fo

Delphi ListView基本用法大全[delphi]

Delphi ListView基本用法大全 本文出处:http://hi.baidu.com/python120/item/4ea85f61af94e55b6895e6ac //增加项或列(字段) ListView1.Clear;ListView1.Columns.Clear;ListView1.Columns.Add;ListView1.Columns.Add;ListView1.Columns.Add;ListView1.Columns.Items[0].Caption:='id';List

Delphi中根据分类数据生成树形结构的最优方法

一. 引言:    TreeView控件适合于表示具有多层次关系的数据.它以简洁的界面,表现形式清晰.形象,操作简单而深受用户喜爱.而且用它可以实现ListView.ListBox所无法实现的很多功能,因而受到广大程序员的青睐.    树形结构在Windows环境中被普遍应用,但在数据库开发中面对层次多.结构复杂的数据,如何快速构造树形目录并实现导航呢?    二. 实现关键技术:    在Delphi提供的控件中包含了TreeView控件,但树的具体形成还需要用户编写代码.即它的列表项要在程序

做了一个浏览指定文件格式的 TreeView(方便查看Source目录下的源码)

unit DirTreeView; interface uses   SysUtils, Classes, Controls, Forms, ComCtrls; type   TDirTreeView = class(TTreeView)   private     FRootPath: string;     FExt: string;     FFileName: string;   protected     procedure Collapse(Node: TTreeNode); ove