溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C#的WinForm怎么增加treeView1控件

發布時間:2021-12-01 09:57:37 來源:億速云 閱讀:196 作者:iii 欄目:編程語言

這篇文章主要講解了“C#的WinForm怎么增加treeView1控件”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“C#的WinForm怎么增加treeView1控件”吧!

使用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   {   ///    /// Form1 的摘要說明。   ///    public class Form1 : System.Windows.Forms.Form   {   private System.Windows.Forms.TreeView treeView1;   ///    /// 必需的設計器變量。   ///    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);   }   ///    /// 清理所有正在使用的資源。   ///    protected override void Dispose( bool disposing )   {   if( disposing )   {   if (components != null)   {   components.Dispose();   }   }   base.Dispose( disposing );   }   #region Windows窗體設計器生成的代碼   ///    ///設計器支持所需的方法-不要使用代碼編輯器修改   /// 此方法的內容。   ///    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   ///    /// 應用程序的主入口點。   ///    [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();   }   }   }

感謝各位的閱讀,以上就是“C#的WinForm怎么增加treeView1控件”的內容了,經過本文的學習后,相信大家對C#的WinForm怎么增加treeView1控件這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女