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

📄 form1.cs

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

    /// <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 button2;
		private System.WinForms.ListBox listBox1;
		private System.WinForms.Button button1;
		private System.WinForms.TextBox textBox1;
		private System.WinForms.Label label1;

        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.textBox1 = new System.WinForms.TextBox ();
			this.button1 = new System.WinForms.Button ();
			this.label1 = new System.WinForms.Label ();
			this.listBox1 = new System.WinForms.ListBox ();
			this.button2 = new System.WinForms.Button ();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			textBox1.Location = new System.Drawing.Point (112, 24);
			textBox1.TabIndex = 1;
			textBox1.Size = new System.Drawing.Size (168, 20);
			button1.Location = new System.Drawing.Point (104, 72);
			button1.Size = new System.Drawing.Size (72, 32);
			button1.TabIndex = 2;
			button1.Text = "&Add";
			button1.Click += new System.EventHandler (this.button1_Click);
			label1.Location = new System.Drawing.Point (24, 32);
			label1.Text = "Enter Name:";
			label1.Size = new System.Drawing.Size (72, 16);
			label1.TabIndex = 0;
			listBox1.Location = new System.Drawing.Point (64, 120);
			listBox1.Size = new System.Drawing.Size (152, 108);
			listBox1.TabIndex = 3;
			listBox1.DoubleClick += new System.EventHandler (this.listBox1_DoubleClick);
			button2.Location = new System.Drawing.Point (96, 240);
			button2.Size = new System.Drawing.Size (75, 23);
			button2.TabIndex = 4;
			button2.Text = "&Done";
			button2.Click += new System.EventHandler (this.button2_Click);
			this.Text = "Form1";
			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
			this.Controls.Add (this.button2);
			this.Controls.Add (this.listBox1);
			this.Controls.Add (this.button1);
			this.Controls.Add (this.textBox1);
			this.Controls.Add (this.label1);
		}

		protected void listBox1_DoubleClick (object sender, System.EventArgs e)
		{
           // Which item did they double click upon?
		   int nIndex = this.listBox1.SelectedIndex;
	       MessageBox.Show("You selected " + nIndex, "Selection", 
			   MessageBox.IconExclamation | MessageBox.OK);
   		}

		protected void button1_Click (object sender, System.EventArgs e)
		{
            if ( this.textBox1.Text.Length != 0)
			{
				this.listBox1.Items.Add( 
					this.textBox1.Text );
				this.textBox1.Text = "";
				this.textBox1.Focus();
			}
		}

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

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