对于浮点数,只需编辑控件 [英] an Edit control , just, for float numbers
本文介绍了对于浮点数,只需编辑控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的VC ++项目中,我想要一个Edit控件,忽略除了整数和Dot(。)之外的所有内容,以便给出浮点数。
我在OnKeyDown()事件中写了一个MyEdit类deived CEdit:
Hi,
In my VC++ project, I want an Edit control that it ignores write anything except integer numbers and Dot(.) for giving float numbers.
I write a MyEdit class deived CEdit, in OnKeyDown() event :
UINT asciiCode = MapVirtualKey(nChar, 2);
if( (asciiCode >= 48 && asciiCode <= 57) || asciiCode == 46)
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
else
nChar = 0;
但编辑框可以提供任何字符!
如何忽略其他字符?
But the Edit Box gives any characters!
How do i ignore other characters?
推荐答案
您可以做的是实现CEdit的类扩展。在OnChar或OnKeyUp事件中,您可以获取控件的文本,必要时检查是否符合要求。
What you can do is to implement a class extension of CEdit. Inside the OnChar or OnKeyUp event you can get the text of your control, check for conformity an correct if necessary.
这篇关于对于浮点数,只需编辑控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文