using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WFrom { public partial class Form5 : Form { public Form5() { InitializeComponent(); this.textBox1.GotFocus += new EventHandler(textBox1_GotFocus); this.KeyDown += new KeyEventHandler(Form1_KeyDown); } void Form1_KeyDown(object sender, KeyEventArgs e) { //请根据自己的需要验证哪些Key需要响应 this.textBox1.Text = e.KeyValue.ToString(); } void textBox1_GotFocus(object sender, EventArgs e) { this.Focus(); } } }