C#winformは、テキストボックスが入力できるのは数字のみであることを認識しています

入力できるのは数字のみであることを認識して
ここに画像の説明を挿入
くださいイベント属性txtDay_KeyPressを使用し
ここに画像の説明を挿入
てコード実装します。

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

おすすめ

転載: blog.csdn.net/caoguanghui0804/article/details/115201069