在C# - WPF中的数字文本框
- 论坛
- 在C# - WPF中的数字文本框
41 浏览
在C# - WPF中的数字文本框
这个问题已经在这里有了答案:
我想在WPF中创建一个只接受数字的文本框...
我已经调研过了,人们说要使用keypress事件或掩码文本框,但它们都是在Windows窗体中...
admin 更改状态以发布 2023年5月22日
匿名的
0 Comments
对于WPF:
private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e) { if (!char.IsDigit(e.Text, e.Text.Length - 1)) e.Handled = true; }
对于Windows表单:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsDigit(e.KeyChar) ) e.Handled = true; }