禁用MaskedTextbox中的一些字母键
我想要一个为十六进制颜色代码制作的蒙版框架,例如“#73E57E”。这意味着仅允许0-9和AF。我的面具是“> aaaaaa”。我不知道的是如何禁用一些字母。因此,当我按下“ G”键时,什么都不会发生。例如,就像我点击“+”密钥一样,将其视为。
这是我到目前为止已经测试过的:
private void mskBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.G)
{
e.Handled = true;
}
}
private void mskBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.H)
{
e.Handled = true;
}
}
I want a MaskedTextBox that is made for hex color codes, such as "#73E57E" for example. This means that only 0-9 and A-F shall be allowed. My mask is ">AAAAAA". What I can't figure out is how do disable some letters. So that when I hit the "G" key, nothing shall happen. Exectly as if I hit the "+" key for example.
This is what I have tested so far:
private void mskBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.G)
{
e.Handled = true;
}
}
private void mskBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.H)
{
e.Handled = true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关闭!尝试抑制按键。这是一种方法:
Close! Try suppressing the KeyPress also. Here's one approach: