文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在C#的WinForm中增加一个treeView1控件

在C#的WinForm中增加一个treeView1控件

时间:2010-09-02  来源:花田错

    使用TreeNode的tag属性放置编码,TreeNode的Text属性放置名称,最简单的示例如下——先添加两个节点,然后处理AfterSelect事件:

    using System;

    using   System.Drawing; using   System.Collections; using   System.ComponentModel; using   System.Windows.Forms; using   System.Data;

    namespace testtree

    {

    /// <summary>

    ///   Form1   的摘要说明。

    /// </summary>

    public   class   Form1   :   System.Windows.Forms.Form

    {

    private   System.Windows.Forms.TreeView   treeView1;

    /// <summary>

    ///   必需的设计器变量。

    /// </summary>

    private   System.ComponentModel.Container   components   =   null;

    public Form1()

    {

    //

    // Windows窗体设计器支持所必需的

    //

    InitializeComponent();

    //

    // TODO:在InitializeComponent调用后添加任何构造函数代码

    //

    TreeNode tn = new TreeNode();

    tn.Tag   =   "1001"; tn.Text   =   "hello";

    TreeNode tn2 = new TreeNode();

    tn2.Tag   =   "1002"; tn2.Text   =   "ok";

    tn.Nodes.Add(tn2);

    treeView1.Nodes.Add(tn);

    }

    /// <summary>

    ///   清理所有正在使用的资源。

    /// </summary>

    protected override void Dispose( bool disposing )

    {

    if( disposing )

    {

    if   (components   !=   null)

    {

    components.Dispose();

    }

    }

    base.Dispose(   disposing   );

    }

    #region Windows窗体设计器生成的代码

    /// <summary>

    ///设计器支持所需的方法-不要使用代码编辑器修改

    ///   此方法的内容。

    /// </summary>

    private void InitializeComponent()

    {

    this.treeView1   =   new   System.Windows.Forms.TreeView(); this.SuspendLayout();

    //

    // treeView1

    //

    this.treeView1.ImageIndex   =   -1; this.treeView1.Location   =   new   System.Drawing.Point(16,   8); this.treeView1.Name   =   "treeView1"; this.treeView1.SelectedImageIndex   =   -1; this.treeView1.TabIndex   =   0; this.treeView1.AfterSelect   +=   new   System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);

    //

    // Form1

    //

    this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14); this.ClientSize   =   new   System.Drawing.Size(292,   266); this.Controls.Add(this.treeView1); this.Name   =   "Form1"; this.Text   =   "Form1"; this.ResumeLayout(false);

    }

    #endregion

    /// <summary>

    ///   www.qichepeijian.com应用程序的主入口点。

    /// </summary>

    [STAThread]

    static void Main()

    {

    Application.Run(new   Form1());

    }

    private   void   treeView1_AfterSelect(object   sender,   System.Windows.Forms.TreeViewEventArgs   e)

    {

    string   s   =   treeView1.SelectedNode.Tag.ToString(); string   s2   =   treeView1.SelectedNode.Text.ToString();

    }

    }

    }

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载