Register an Event

If an event is not registered, you can register it by the following ways.

The first way, you can register it in textBox1's Properties, just as shown below.

 

The second way, you can register it in "Form1_Load", just like the code as follows.

private void Form1_Load(object sender, EventArgs e)
{
    textBox1.KeyPress += textBox1_KeyPress;
}
原文地址:https://www.cnblogs.com/jizhiqiliao/p/9897019.html