为给定角色设置遮罩 [英] Set mask for a given character

查看:59
本文介绍了为给定角色设置遮罩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows窗体中,我有一个maskedtext框.对于此文本框,用户只能键入一个字符.并且该字符必须为"Y"或"N".不允许使用其他字符.在这种情况下,如何使用mask属性.

In my windows form I have a maskedtext box. For this text box user can type only a single character. And that character must be the "Y" or "N". Other characters not allowed for this. How can I use mask property for this case.

推荐答案

您可以使用TextChanged事件处理程序.
检查文本是否为"Y"或"N",清除文本框并根据需要显示消息.无需遮罩.这对于单字母文本框会很好用.

您可以改用dropdownlist.
You can use TextChanged event handler.
Check if the text is not "Y" or "N", clear the textbox and show message if required. There is no need to mask. This would work fine for single letter textbox.

You can use dropdownlist instead.


为什么这么复杂和令人困惑?只需使用太单选按钮:是",否".更好的是,一个复选框我确认"或其他内容.

—SA
Why so complex and confusing way? Simply use too radio buttons: "Yes", "No". Better yet, one check box "I confirm it" or something.

—SA


我认为,最接近的可能是使用掩码值"L"-这会将输入限制为一个字母.然后,您将必须应用自己的附加验证来确定该值是否有效(即Y或N)

请问您为什么使用文本框?看来您更适合针对此类UI行为使用复选框或下拉列表
I think perhaps the closest is to use the mask value of "L" - this will restrict the input to only one letter. You would then have to apply your own additional validation to decide if that value is valid (i.e. Y or N)

Can I ask why you are using a textbox thou? It seems you would be better suited to use a checkbox or a dropdownlist for this kind of UI behaviour


这篇关于为给定角色设置遮罩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆