如何使文本框仅接受十六进制十进制值? [英] How to make the textbox to accept only Hexa decimal values?

查看:105
本文介绍了如何使文本框仅接受十六进制十进制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使文本框仅接受十六进制十进制值?还应该只包含两个字符吗?

How to make the textbox to accept only Hexa decimal values?And also it should take only two characters in it?

推荐答案

有很多方法可以做到这一点.
一种可重用的方式是.
创建派生自CEdit的类(CHexEdit)
覆盖CHexEdit类中的PreTranslateMessage()函数
请按照以下方式进行检查

there are many way to do this.
one resusable way is that.
Create your class (CHexEdit) derived from CEdit
override the PreTranslateMessage() function in CHexEdit class
do following kind of checking in it

if( pMsg->message == WM_CHAR )
{
    if(( pMsg->wParam  != ''A'' ) )// It allows to enter only ''A'' in your edit box
    {
        pMsg->wParam = 0;
    }
}



而不是if((pMsg-> wParam!=``A'')),您需要编写自己的条件检查以仅允许0到9之间的字符以及``a''和``f''和`` A''和``F''支持十六进制

现在您必须创建编辑控件的控件成员变量.其类类型应为HexEdit而不是CEdit



instead of if(( pMsg->wParam != ''A'' ) ) you need to write your own condition checking for allowing characters only between 0 and 9 and ''a'' and ''f'' and ''A'' and ''F'' to support hexadecimal

now you have to create control meber variable of your edit control.its class type should be HexEdit instead of CEdit


如果要使用MFC,在这种情况下,最好的选择是屏蔽编辑控制.
这是一篇介绍所有内容的文章:
屏蔽的编辑控件 [
If you want to use MFC, the best option in this case would be masked edit control.
Here is an article which explains everything:
Masked Edit Control[^].

—SA


这篇关于如何使文本框仅接受十六进制十进制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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