zoukankan      html  css  js  c++  java
  • 学习 TTreeView [2] Items.Item[i]、Items[i]、.Text、SetFocus(设置焦点)、Select(选择)

    本例效果图:



    源码:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls;
    
    type
      TForm1 = class(TForm)
        TreeView1: TTreeView;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    var
      i: Integer;
    
    {这四个按钮的功能是一模一样的}
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Self.Text := TreeView1.Items.Item[i].Text;
      if i < TreeView1.Items.Count-1 then Inc(i) else i := 0;
    
      TreeView1.SetFocus;
      TreeView1.Select(TreeView1.Items.Item[i]);
    end;
    
    {TreeView1.Items.Item[i] 是默认属性, 可以简写为: TreeView1.Items[i]}
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      Text := TreeView1.Items[i].Text;
      if i < TreeView1.Items.Count-1 then Inc(i) else i := 0;
    
      TreeView1.SetFocus;
      TreeView1.Select(TreeView1.Items[i]);
    end;
    
    {每个元素都是 TTreeNode 类型的}
    procedure TForm1.Button3Click(Sender: TObject);
    var
      node: TTreeNode;
    begin
      node := TreeView1.Items[i];
      Text := node.Text;
      if i < TreeView1.Items.Count-1 then Inc(i) else i := 0;
    
      TreeView1.SetFocus;
      TreeView1.Select(node);
    end;
    
    {尽量使用 TTreeNodes 与 TTreeNode}
    procedure TForm1.Button4Click(Sender: TObject);
    var
      Nodes: TTreeNodes;
      node: TTreeNode;
    begin
      Nodes := TreeView1.Items;
      node := Nodes[i];
      Text := node.Text;
      if i < Nodes.Count-1 then Inc(i) else i := 0;
    
      TreeView1.SetFocus;
      TreeView1.Select(node);
    end;
    
    end.
    
  • 相关阅读:
    jQuery.ajax()方法笔记
    Docker安装
    Linux下Nginx+keepalived实现高可用
    Linux安装Nginx
    Redis主从、哨兵、Cluster特性
    Linux搭建redis集群
    Linux搭建redis单机
    HashMap知识总结(jdk1.8)
    如何避免form提交进行页面跳转
    异步上传文件,jquery+ajax,显示进度条
  • 原文地址:https://www.cnblogs.com/del/p/1099762.html
Copyright © 2011-2022 走看看