原来的样例是用MESSAGEBOX来输出,我改成用RICHTEXT来输出。好看点哈。
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 using System.IO; 11 12 namespace WindowsFormsApplication1 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 if (openFileDialog1.ShowDialog() == DialogResult.OK) 24 { 25 textBox1.Text = openFileDialog1.FileName; 26 FileInfo finfo = new FileInfo(textBox1.Text); 27 string strCTime, strLATime, strLWTime, strName, strFName, strDName, strISRead, lgLength; 28 string strContent; 29 strCTime = finfo.CreationTime.ToShortDateString(); 30 strLATime = finfo.LastAccessTime.ToShortDateString(); 31 strLWTime = finfo.LastWriteTime.ToShortDateString(); 32 strName = finfo.Name; 33 strFName = finfo.FullName; 34 strDName = finfo.DirectoryName; 35 strISRead = finfo.IsReadOnly.ToString(); 36 lgLength = finfo.Length.ToString(); 37 38 strContent = "文件信息:\n创建时间: "+ strCTime + 39 "\n上次访问时间:" + strLATime + 40 "\n上次写入时间:" + strLWTime + 41 "\n文件名称:" + strName + 42 "\n完整目录:" + strFName + 43 "\n完整路径:" + strDName + 44 "\n是否只读:" + strISRead + 45 "\n文件长度:" + lgLength; 46 richTextBox1.Text = strContent; 47 } 48 } 49 } 50 }