C#winform realizes that the text box can only input numbers

Realize that only numbers can be input.
Insert picture description here
Use the event attribute txtDay_KeyPress to
Insert picture description here
implement the code

  private void txtDay_KeyPress(object sender, KeyPressEventArgs e)
        {       
            if (!(char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
            {
                e.Handled = true;
            }
        }

Guess you like

Origin blog.csdn.net/caoguanghui0804/article/details/115201069