程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> Visual C#構建網絡計算機樹形圖(3)

Visual C#構建網絡計算機樹形圖(3)

編輯:關於C語言

10. 以下面代碼替代系統產生的InitializeComponent過程,下列代碼的作用是初始化程序中的組件,並定義treeVIEw1組件的DoubleClick事件:

private void InitializeComponent ( )
{
 this.treeView1 = new System.Windows.Forms.TreeVIEw ( ) ;
 this.button1 = new System.Windows.Forms.Button ( ) ;
 this.SuspendLayout ( ) ;
 this.treeVIEw1.ImageIndex = -1;
 this.treeVIEw1.Location = new System.Drawing.Point ( 16 , 8 ) ;
 this.treeView1.Name = "treeVIEw1" ;
 this.treeVIEw1.SelectedImageIndex = -1 ;
 this.treeVIEw1.Size = new System.Drawing.Size ( 316 , 302 ) ;
 this.treeVIEw1.TabIndex = 0 ;
 this.treeView1.DoubleClick += new System.EventHandler ( this.treeVIEw1_DoubleClick ) ;
 this.button1.Location = new System.Drawing.Point ( 118 , 324 ) ;
 this.button1.Name = "button1" ;
 this.button1.Size = new System.Drawing.Size ( 82 , 34 ) ;
 this.button1.TabIndex = 1 ;
 this.button1.Text = "獲取" ;
 this.button1.Click += new System.EventHandler ( this.button1_Click ) ;
 this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ;
 this.ClIEntSize = new System.Drawing.Size ( 350 , 369 ) ;
 this.Controls.Add ( this.button1 ) ;
 this.Controls.Add ( this.treeVIEw1 ) ;
 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle ;
 this.MaximizeBox = false ;
 this.Name = "Form1" ;
 this.Text = "Visual C#構建網絡計算機樹形圖" ;
 this.ResumeLayout ( false ) ;
}

至此【Visual C#構建網絡計算機樹形圖】項目的界面設計和功能實現的准備工作就完成了,設計後的界面如圖01所示:

圖01:【Visual C#構建網絡計算機樹形圖】項目的設計界面

11. 用下列代碼替換Form1.cs中的button1的Click事件對應的處理代碼,下列代碼讀取網絡中域或工作組,並加入到樹形圖中:

private void button1_Click ( object sender , System.EventArgs e )
{
 foreach ( DirectoryEntry child in entryPC.Children )
 {
  TreeNode node = new TreeNode ( ) ;
  node.Text = child.Name ;
  treeVIEw1.Nodes.Add ( node ) ;
  //在treeVIEw1組件中添加節點
 }
 //利用foreach語句實現對網絡域和工作組的遍歷,
 //並通過treeVIEw1組件顯示出來
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved