c# - 如果 TextBox 有 8 个字符 xaml C#,则将其清除
解决方案
处理文本框的KeyDown
事件并检查textBox.Text.Length == 8
. 您还可以强制每个其他字符为空格。
未经测试- 可能需要根据空格适合 8 个字符的方式进行调整。如果是 4 个字符,它们之间有空格,则只有 7 个字符。
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (textBox1.Text.Length == 8)
{
// do something with the text
textBox1.Text = ""; // clear the textbox
}
// optional else if to only allow spaces for every other character
else if (textBox1.Text.Length % 2 == 1 // odd index characters
&& e.KeyCode != Keys.Space) // must be spaces
{
e.Handled = true;
}
}
推荐阅读
- git - Android Studio Git 推送到 bitbucket 被拒绝
- ios - 简单英语的 iOS 电源状态
- python - 修改pandas MultiIndex DataFrame中每组的最后一行
- haskell - Haskell/GHC - Haskell 有没有办法只返回 16 位小数?
- amazon-ec2 - 食谱与手动设置 statsD/metric 收集服务器?
- database - 颤振搜索用户名是否存在
- javascript - React JS 和 CSS,向上滚动数据库中的所有文本评论
- batch-file - 在不关闭 explorer.exe 的情况下刷新图标缓存
- python - 我将如何创建一个具有 aa 列的唯一值并对其进行计数的新数据框?
- javascript - 如何在 YouTube 上以编程方式加载评论部分?(无滚动)(JS/HTML/DOM)