電話番号を挿入するためのテキストボックスを作成しました。数字、削除ボタン、ハイフンキーだけを押してほしい。私は次のコードを使用しました:それは削除ボタンと数字のために働きます、私はハイフンのために何をすべきですか?
private void ContactNumTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
const char Hyphen = (char)2d;
const char Delete = (char)8;
if (char.IsNumber(e.KeyChar) && e.KeyChar != Hyphen && e.KeyChar!= Delete)
e.Handled = true;
}