代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace testListViewApp
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ImageList imageListLarge;
private System.Windows.Forms.ImageList imageListSmall;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ListView MyListView;
private System.Windows.Forms.RadioButton rdBtnLarge;
private System.Windows.Forms.RadioButton rdBtnSmall;
private System.Windows.Forms.RadioButton rdBtnList;
private System.Windows.Forms.RadioButton rdBtnDetail;
private System.ComponentModel.IContainer components;
public Form1()
{
InitializeComponent(); }
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.MyListView = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.imageListLarge = new System.Windows.Forms.ImageList(this.components);
this.imageListSmall = new System.Windows.Forms.ImageList(this.components);
this.rdBtnLarge = new System.Windows.Forms.RadioButton();
this.rdBtnSmall = new System.Windows.Forms.RadioButton();
this.rdBtnList = new System.Windows.Forms.RadioButton();
this.rdBtnDetail = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// MyListView
//
this.MyListView.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.MyListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3, this.columnHeader4});
this.MyListView.GridLines = true;
this.MyListView.LargeImageList = this.imageListLarge;
this.MyListView.Location = new System.Drawing.Point(1, 75);
this.MyListView.Name = "MyListView";
this.MyListView.Size = new System.Drawing.Size(299, 284);
this.MyListView.SmallImageList = this.imageListSmall;
this.MyListView.TabIndex = 0;
//
// columnHeader1
//
this.columnHeader1.Text = "名称";
//
// columnHeader2
//
this.columnHeader2.Text = "属性";
//
// columnHeader3
//
this.columnHeader3.Text = "访问时间";
//
// columnHeader4
//
this.columnHeader4.Text = "类型";
//
// imageListLarge
//
this.imageListLarge.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageListLarge.ImageSize = new System.Drawing.Size(16, 16);
this.imageListLarge.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListLarge.ImageStream")));
this.imageListLarge.TransparentColor = System.Drawing.Color.Transparent;
//
// imageListSmall
//
this.imageListSmall.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageListSmall.ImageSize = new System.Drawing.Size(16, 16);
this.imageListSmall.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListSmall.ImageStream")));
this.imageListSmall.TransparentColor = System.Drawing.Color.Transparent;
//
// rdBtnLarge
//
this.rdBtnLarge.Checked = true;
this.rdBtnLarge.Location = new System.Drawing.Point(24, 16);
this.rdBtnLarge.Name = "rdBtnLarge";
this.rdBtnLarge.TabIndex = 1;
this.rdBtnLarge.TabStop = true;
this.rdBtnLarge.Text = "LargeIcon";
this.rdBtnLarge.CheckedChanged += new System.EventHandler(this.rdBtnLarge_CheckedChanged);
//
// rdBtnSmall
//
this.rdBtnSmall.Location = new System.Drawing.Point(24, 40);
this.rdBtnSmall.Name = "rdBtnSmall";
this.rdBtnSmall.TabIndex = 2;
this.rdBtnSmall.Text = "SmallIcon";
this.rdBtnSmall.CheckedChanged += new System.EventHandler(this.rdBtnSmall_CheckedChanged);
//
// rdBtnList
//
this.rdBtnList.Location = new System.Drawing.Point(160, 16);
this.rdBtnList.Name = "rdBtnList";
this.rdBtnList.TabIndex = 3;
this.rdBtnList.Text = "List";
this.rdBtnList.CheckedChanged += new System.EventHandler(this.rdBtnList_CheckedChanged);
//
// rdBtnDetail
//
this.rdBtnDetail.Location = new System.Drawing.Point(160, 40);
this.rdBtnDetail.Name = "rdBtnDetail";
this.rdBtnDetail.TabIndex = 4;
this.rdBtnDetail.Text = "Detail";
this.rdBtnDetail.CheckedChanged += new System.EventHandler(this.rdBtnDetail_CheckedChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(304, 333);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.rdBtnDetail,
this.rdBtnList,
this.rdBtnSmall,
this.rdBtnLarge,
this.MyListView});
this.Name = "Form1";
this.Text = "testListView";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
foreach (string dirName in Directory.GetDirectories (@"C:\") )
{
ListViewItem aItem = new ListViewItem(dirName,0);
aItem.ImageIndex = 0;
string dirInfo;
dirInfo = File.GetAttributes(dirName).ToString () ;
aItem.SubItems.Add(dirInfo);
dirInfo = File.GetLastAccessTime(dirName).ToString () ;
aItem.SubItems.Add(dirInfo);
aItem.SubItems.Add("目录");
MyListView.Items.Add (aItem);
}
foreach (string fileName in Directory.GetFiles (@"C:\"))
{
ListViewItem aItem = new ListViewItem(fileName,0);
aItem.ImageIndex = 1;
string fileInfo;
fileInfo = File.GetAttributes(fileName).ToString () ;
aItem.SubItems.Add(fileInfo);
fileInfo = File.GetLastAccessTime(fileName).ToString () ;
aItem.SubItems.Add(fileInfo);
aItem.SubItems.Add("文件");
MyListView.Items.Add (aItem);
}
}
private void rdBtnLarge_CheckedChanged(object sender, System.EventArgs e)
{
if (rdBtnLarge.Checked )
{
MyListView.View = View.LargeIcon ;
}
} private void rdBtnSmall_CheckedChanged(object sender, System.EventArgs e)
{
if (rdBtnSmall.Checked )
{
MyListView.View = View.SmallIcon ;
} } private void rdBtnList_CheckedChanged(object sender, System.EventArgs e)
{
if (rdBtnList.Checked )
{
MyListView.View = View.List ;
} } private void rdBtnDetail_CheckedChanged(object sender, System.EventArgs e)
{
if (rdBtnDetail.Checked )
{
MyListView.View = View.Details ;
} }
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace testListViewApp
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ImageList imageListLarge;
private System.Windows.Forms.ImageList imageListSmall;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ListView MyListView;
private System.Windows.Forms.RadioButton rdBtnLarge;
private System.Windows.Forms.RadioButton rdBtnSmall;
private System.Windows.Forms.RadioButton rdBtnList;
private System.Windows.Forms.RadioButton rdBtnDetail;
private System.ComponentModel.IContainer components;
public Form1()
{
InitializeComponent(); }
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.MyListView = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.imageListLarge = new System.Windows.Forms.ImageList(this.components);
this.imageListSmall = new System.Windows.Forms.ImageList(this.components);
this.rdBtnLarge = new System.Windows.Forms.RadioButton();
this.rdBtnSmall = new System.Windows.Forms.RadioButton();
this.rdBtnList = new System.Windows.Forms.RadioButton();
this.rdBtnDetail = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// MyListView
//
this.MyListView.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.MyListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3, this.columnHeader4});
this.MyListView.GridLines = true;
this.MyListView.LargeImageList = this.imageListLarge;
this.MyListView.Location = new System.Drawing.Point(1, 75);
this.MyListView.Name = "MyListView";
this.MyListView.Size = new System.Drawing.Size(299, 284);
this.MyListView.SmallImageList = this.imageListSmall;
this.MyListView.TabIndex = 0;
//
// columnHeader1
//
this.columnHeader1.Text = "名称";
//
// columnHeader2
//
this.columnHeader2.Text = "属性";
//
// columnHeader3
//
this.columnHeader3.Text = "访问时间";
//
// columnHeader4
//
this.columnHeader4.Text = "类型";
//
// imageListLarge
//
this.imageListLarge.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageListLarge.ImageSize = new System.Drawing.Size(16, 16);
this.imageListLarge.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListLarge.ImageStream")));
this.imageListLarge.TransparentColor = System.Drawing.Color.Transparent;
//
// imageListSmall
//
this.imageListSmall.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageListSmall.ImageSize = new System.Drawing.Size(16, 16);
this.imageListSmall.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListSmall.ImageStream")));
this.imageListSmall.TransparentColor = System.Drawing.Color.Transparent;
//
// rdBtnLarge
//
this.rdBtnLarge.Checked = true;
this.rdBtnLarge.Location = new System.Drawing.Point(24, 16);
this.rdBtnLarge.Name = "rdBtnLarge";
this.rdBtnLarge.TabIndex = 1;
this.rdBtnLarge.TabStop = true;
this.rdBtnLarge.Text = "LargeIcon";
this.rdBtnLarge.CheckedChanged += new System.EventHandler(this.rdBtnLarge_CheckedChanged);
//
// rdBtnSmall
//
this.rdBtnSmall.Location = new System.Drawing.Point(24, 40);
this.rdBtnSmall.Name = "rdBtnSmall";
this.rdBtnSmall.TabIndex = 2;
this.rdBtnSmall.Text = "SmallIcon";
this.rdBtnSmall.CheckedChanged += new System.EventHandler(this.rdBtnSmall_CheckedChanged);
//
// rdBtnList
//
this.rdBtnList.Location = new System.Drawing.Point(160, 16);
this.rdBtnList.Name = "rdBtnList";
this.rdBtnList.TabIndex = 3;
this.rdBtnList.Text = "List";
this.rdBtnList.CheckedChanged += new System.EventHandler(this.rdBtnList_CheckedChanged);
//
// rdBtnDetail
//
this.rdBtnDetail.Location = new System.Drawing.Point(160, 40);
this.rdBtnDetail.Name = "rdBtnDetail";
this.rdBtnDetail.TabIndex = 4;
this.rdBtnDetail.Text = "Detail";
this.rdBtnDetail.CheckedChanged += new System.EventHandler(this.rdBtnDetail_CheckedChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(304, 333);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.rdBtnDetail,
this.rdBtnList,
this.rdBtnSmall,
this.rdBtnLarge,
this.MyListView});
this.Name = "Form1";
this.Text = "testListView";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
foreach (string dirName in Directory.GetDirectories (@"C:\") )
{
ListViewItem aItem = new ListViewItem(dirName,0);
aItem.ImageIndex = 0;
string dirInfo;
dirInfo = File.GetAttributes(dirName).ToString () ;
aItem.SubItems.Add(dirInfo);
dirInfo = File.GetLastAccessTime(dirName).ToString () ;
aItem.SubItems.Add(dirInfo);
aItem.SubItems.Add("目录");
MyListView.Items.Add (aItem);
}
foreach (string fileName in Directory.GetFiles (@"C:\"))
{
ListViewItem aItem = new ListViewItem(fileName,0);
aItem.ImageIndex = 1;
string fileInfo;
fileInfo = File.GetAttributes(fileName).ToString () ;
aItem.SubItems.Add(fileInfo);
fileInfo = File.GetLastAccessTime(fileName).ToString () ;
aItem.SubItems.Add(fileInfo);
aItem.SubItems.Add("文件");
MyListView.Items.Add (aItem);
}
}
private void rdBtnLarge_CheckedChanged(object sender, System.EventArgs e)
{
if (rdBtnLarge.Checked )
{
MyListView.View = View.LargeIcon ;
}
} private void rdBtnSmall_CheckedChanged(object sender, System.EventArgs e)
{
if (rdBtnSmall.Checked )
{
MyListView.View = View.SmallIcon ;
} } private void rdBtnList_CheckedChanged(object sender, System.EventArgs e)
{
if (rdBtnList.Checked )
{
MyListView.View = View.List ;
} } private void rdBtnDetail_CheckedChanged(object sender, System.EventArgs e)
{
if (rdBtnDetail.Checked )
{
MyListView.View = View.Details ;
} }
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货