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

📄 form1.cs

📁 《c#技术内幕代码》
💻 CS
字号:
namespace Ch9_11
{
    using System;
	using System.IO;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

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

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

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <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.Windows.Forms.Button ();
			this.label1 = new System.Windows.Forms.Label ();
			this.button3 = new System.Windows.Forms.Button ();
			this.button2 = new System.Windows.Forms.Button ();
			this.textBox1 = new System.Windows.Forms.TextBox ();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			button1.Location = new System.Drawing.Point (248, 24);
			button1.Size = new System.Drawing.Size (75, 23);
			button1.TabIndex = 2;
			button1.Text = "&Browse";
			button1.Click += new System.EventHandler (this.button1_Click);
			label1.Location = new System.Drawing.Point (16, 24);
			label1.Text = "Enter a file name:";
			label1.Size = new System.Drawing.Size (100, 16);
			label1.TabIndex = 1;
			button3.Location = new System.Drawing.Point (184, 64);
			button3.Size = new System.Drawing.Size (75, 23);
			button3.TabIndex = 4;
			button3.Text = "&Close";
			button3.Click += new System.EventHandler (this.button3_Click);
			button2.Location = new System.Drawing.Point (64, 64);
			button2.Size = new System.Drawing.Size (75, 23);
			button2.TabIndex = 3;
			button2.Text = "&Ok";
			button2.Click += new System.EventHandler (this.button2_Click);
			textBox1.Location = new System.Drawing.Point (120, 24);
			textBox1.TabIndex = 0;
			textBox1.Size = new System.Drawing.Size (100, 20);
			this.Text = "Form1";
			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
			this.ClientSize = new System.Drawing.Size (352, 101);
			this.Controls.Add (this.button3);
			this.Controls.Add (this.button2);
			this.Controls.Add (this.button1);
			this.Controls.Add (this.label1);
			this.Controls.Add (this.textBox1);
		}

		protected void button3_Click (object sender, System.EventArgs e)
		{
            Close();
		}

		protected void button2_Click (object sender, System.EventArgs e)
		{
            // See if they entered something
			if ( textBox1.Text.Length != 0 )
			{
				if ( File.Exists( this.textBox1.Text ) )
				{
					MessageBox.Show(this, "Valid File!");
					Close();
				}
				else
					MessageBox.Show(this, "Invalid File Name!!");

			}
		}

		protected void button1_Click (object sender, System.EventArgs e)
		{
            FileDialog fd = new OpenFileDialog();
			if ( fd.ShowDialog() == System.Windows.Forms.DialogResult.OK )
			{
				textBox1.Text = fd.FileName;
			}
		}

        /// <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 + -