求C#WinForm中将文件目录生成一个treeview的代码

求C#WinForm中将文件目录生成一个treeview的代码,第1张

namespace case0706_11

{

partial class Form1

{

/// <summary>

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

/// </summary>

private System.ComponentModel.IContainer components = null

/// <summary>

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

/// </summary>

/// <param name="disposing">如果应释放托管资源,为 true;否则伏唤为 false。</param>

protected override void Dispose(bool disposing)

{

if (disposing &&(components != null))

{

components.Dispose()

}

base.Dispose(disposing)

}

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

/// <summary>

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///棚厅枝 </summary>

private void InitializeComponent()

{

this.groupBox1 = new System.Windows.Forms.GroupBox()

this.groupBox2 = new System.Windows.Forms.GroupBox()

this.listView1 = new System.Windows.Forms.ListView()

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

this.columnHeader1 = new System.Windows.Forms.ColumnHeader()

this.columnHeader2 = new System.Windows.Forms.ColumnHeader()

this.columnHeader3 = new System.Windows.Forms.ColumnHeader()

this.groupBox1.SuspendLayout()

this.groupBox2.SuspendLayout()

this.SuspendLayout()

//

// groupBox1

//

this.groupBox1.Controls.Add(this.treeView1)

this.groupBox1.Location = new System.Drawing.Point(5, 6)

this.groupBox1.Name = "groupBox1"

this.groupBox1.Size = new System.Drawing.Size(146, 284)

this.groupBox1.TabIndex = 0

this.groupBox1.TabStop = false

this.groupBox1.Text = "目链敏录信息"

//

// groupBox2

//

this.groupBox2.Controls.Add(this.listView1)

this.groupBox2.Location = new System.Drawing.Point(171, 6)

this.groupBox2.Name = "groupBox2"

this.groupBox2.Size = new System.Drawing.Size(301, 284)

this.groupBox2.TabIndex = 1

this.groupBox2.TabStop = false

this.groupBox2.Text = "文件信息"

//

// listView1

//

this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {

this.columnHeader1,

this.columnHeader2,

this.columnHeader3})

this.listView1.FullRowSelect = true

this.listView1.GridLines = true

this.listView1.Location = new System.Drawing.Point(1, 18)

this.listView1.MultiSelect = false

this.listView1.Name = "listView1"

this.listView1.Size = new System.Drawing.Size(300, 262)

this.listView1.TabIndex = 0

this.listView1.UseCompatibleStateImageBehavior = false

this.listView1.View = System.Windows.Forms.View.Details

//

// treeView1

//

this.treeView1.Location = new System.Drawing.Point(0, 18)

this.treeView1.Name = "treeView1"

this.treeView1.Size = new System.Drawing.Size(145, 265)

this.treeView1.TabIndex = 0

this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick)

//

// columnHeader1

//

this.columnHeader1.Text = "名称"

this.columnHeader1.Width = 120

//

// columnHeader2

//

this.columnHeader2.Text = "大小"

//

// columnHeader3

//

this.columnHeader3.Text = "修改时间"

this.columnHeader3.Width = 120

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F)

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

this.ClientSize = new System.Drawing.Size(484, 302)

this.Controls.Add(this.groupBox2)

this.Controls.Add(this.groupBox1)

this.Name = "Form1"

this.Text = "TreeView遍历磁盘目录"

this.Load += new System.EventHandler(this.Form1_Load)

this.groupBox1.ResumeLayout(false)

this.groupBox2.ResumeLayout(false)

this.ResumeLayout(false)

}

#endregion

private System.Windows.Forms.GroupBox groupBox1

private System.Windows.Forms.TreeView treeView1

private System.Windows.Forms.GroupBox groupBox2

private System.Windows.Forms.ListView listView1

private System.Windows.Forms.ColumnHeader columnHeader1

private System.Windows.Forms.ColumnHeader columnHeader2

private System.Windows.Forms.ColumnHeader columnHeader3

}

}

“ System.Windows.Forms.Application.StartupPath”:获取当前应用程序所在目录的路径,最后不包含“\”;

“Environment.CurrentDirectory”:获取当前应用程毕巧裤序的路径,宽磨最后不包含“\”;

“System.IO.Directory.GetCurrentDirectory”:获取当前应用程序的路径,最后不包含“\”;

以上方法Win7下均可获得程序当前路径,XP下Environment.CurrentDirectory获取手简的路径信息为默认 *** 作目录。

之后使用System.IO.Directory.GetParent()得到目录的上一层。

我在之前做过一个FTP的客户端工具。 drw 文件夹 -rw 文件(有扩展名或无扩展名)明洞则 我是根据服务端返回的报文进行分析获取的列表。 给你一激棚些代码片段: /// /// 获取指定目录下的文件和文件夹。 /// /// 要获取的目颤困录 /// 要发送到FTP服务器的密令


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8213618.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存