简体   繁体   English

如何使用 wxFloatingPointValidator 过滤 wxTextCtrl?

[英]How do I use wxFloatingPointValidator to filter wxTextCtrl?

I have found a possible solution at Formatting wx.TextCtrl with numeric values only - float precision我在Formatting wx.TextCtrl with numeric values 找到了一个可能的解决方案 - 浮点精度

But I am not able to use it in my program.但我无法在我的程序中使用它。

I used the header #include <wx/valnum.h>我使用了 header #include <wx/valnum.h>

and added the following code to my main.h并将以下代码添加到我的 main.h

 wxFloatingPointValidator<double> _val(2,&_myValue,wxNUM_VAL_ZERO_AS_BLANK);

 _val.SetRange(0.,100.);     // set allowable range

But it is showing errors:但它显示错误:

expected identifier before numeric constant数字常量之前的预期标识符

_val does not name a type _val 没有命名类型

It's often a good idea to grep for the class you're trying to use in the samples subdirectory of wxWidgets.对于您尝试在 wxWidgets 的示例子目录中使用的 class,grep 通常是一个好主意。 In this particular case you can find a working example of using it in samples/validate/validate.cpp , please have a look at it.在这种特殊情况下,您可以在samples/validate/validate.cpp中找到使用它的工作示例,请查看它。

As for the error you're getting, it's really impossible to say what goes wrong as you don't show the complete code nor even say on which line does it happen.至于你得到的错误,真的不可能说出哪里出了问题,因为你没有显示完整的代码,甚至没有说它发生在哪一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM