我想在 WPF 中创建一个只接受数字的文本框...
我研究过,人们说使用按键事件或屏蔽文本框,但它们是在 Windows 窗体中......
For 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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)