⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
namespace WinApp_FileInfo
{
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.WinForms;
    using System.Data;
	using System.IO;

    /// <summary>
    ///    Summary description for Form1.
    /// </summary>
    public class Form1 : System.WinForms.Form
    {
        /// <summary>
        ///    Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components;
		private System.WinForms.Button button1;
		private System.WinForms.Label label1;
		private System.WinForms.TextBox textBox1;
		private System.WinForms.ListBox listBox1;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
       private int iItems=0;
       public void AddItem(string sItem)
       {
       listBox1.InsertItem(iItems,sItem);
       ++iItems;
       }
		/// <summary>
        ///    Clean up any resources being used.
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();
            components.Dispose();
        }

        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container ();
			this.button1 = new System.WinForms.Button ();
			this.label1 = new System.WinForms.Label ();
			this.textBox1 = new System.WinForms.TextBox ();
			this.listBox1 = new System.WinForms.ListBox ();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			button1.Location = new System.Drawing.Point (296, 32);
			button1.Size = new System.Drawing.Size (64, 24);
			button1.TabIndex = 3;
			button1.Text = "确定";
			button1.Click += new System.EventHandler (this.button1_Click);
			label1.Location = new System.Drawing.Point (16, 32);
			label1.Text = "请输入文件名:";
			label1.Size = new System.Drawing.Size (96, 24);
			label1.TabIndex = 2;
			label1.Click += new System.EventHandler (this.label1_Click);
			textBox1.Location = new System.Drawing.Point (136, 32);
			textBox1.TabIndex = 1;
			textBox1.Size = new System.Drawing.Size (144, 21);
			listBox1.Location = new System.Drawing.Point (32, 96);
			listBox1.Size = new System.Drawing.Size (296, 172);
			listBox1.TabIndex = 0;
			this.Text = "Form1";
			this.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
			this.ClientSize = new System.Drawing.Size (384, 273);
			this.Controls.Add (this.button1);
			this.Controls.Add (this.label1);
			this.Controls.Add (this.textBox1);
			this.Controls.Add (this.listBox1);
		}

		protected void button1_Click (object sender, System.EventArgs e)
		{
			string filename;
			filename=textBox1.Text;
			File fl=new File(@filename);
			AddItem("Connected to the file:"+fl.Name);
            AddItem("In Folders:"+fl.Directory);
			AddItem("Full Path:"+fl.FullName);
			AddItem("Is Directory:"+fl.IsDirectory.ToString());
			AddItem("Is File:"+fl.IsFile);
			AddItem("Last written time:"+fl.LastWriteTime.ToString());
			AddItem("Last access time:"+fl.LastAccessTime);
			AddItem("The size of file:"+fl.Length);
			AddItem("The creation time of the file:"+fl.CreationTime);
			AddItem("The type of the file:"+fl.GetType());

		}

		protected void label1_Click (object sender, System.EventArgs e)
		{

		}

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void Main(string[] args) 
        {
            Application.Run(new Form1());
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -