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

📄 form1.cs

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

	public class NumericInput : System.WinForms.TextBox
	{
		protected override bool ProcessKeyEventArgs(ref Message m)
		{
			if ( m.msg == 0x0102 ) // WM_CHAR
			{
				char c = (char)m.wParam;
				if ( c < '0' || c > '9')
				{
					return true;
				}
			}
			return base.ProcessKeyEventArgs(ref m);
		}
	}

    /// <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.TextBox textBox2;
		private System.WinForms.Label label2;
		private System.WinForms.Button button1;
		private System.WinForms.Label label1;
		private NumericInput 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.WinForms.Button ();
			this.label1 = new System.WinForms.Label ();
			this.label2 = new System.WinForms.Label ();
			this.textBox2 = new System.WinForms.TextBox ();
			this.textBox1 = new NumericInput();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			button1.Location = new System.Drawing.Point (176, 136);
			button1.Size = new System.Drawing.Size (75, 23);
			button1.TabIndex = 2;
			button1.Text = "&Close";
			button1.Click += new System.EventHandler (this.button1_Click);
			label1.Location = new System.Drawing.Point (32, 32);
			label1.Text = "Enter NUMBERS!";
			label1.Size = new System.Drawing.Size (100, 23);
			label1.TabIndex = 1;
			label2.Location = new System.Drawing.Point (32, 56);
			label2.Text = "Auto-Complete";
			label2.Size = new System.Drawing.Size (96, 24);
			label2.TabIndex = 3;
			textBox2.Location = new System.Drawing.Point (168, 64);
			textBox2.Text = "textBox2";
			textBox2.TabIndex = 4;
			textBox2.Size = new System.Drawing.Size (248, 20);
			textBox1.Location = new System.Drawing.Point (168, 32);
			textBox1.TabIndex = 0;
			textBox1.Size = new System.Drawing.Size (248, 20);
			this.Text = "Form1";
			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
			this.ClientSize = new System.Drawing.Size (456, 165);
			this.Controls.Add (this.textBox2);
			this.Controls.Add (this.label2);
			this.Controls.Add (this.button1);
			this.Controls.Add (this.label1);
			this.Controls.Add (this.textBox1);
		}


		protected void button1_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 + -