强制NumericUpDown控件仅接受2的幂 [英] Forcing a NumericUpDown control to only accept powers of two

查看:66
本文介绍了强制NumericUpDown控件仅接受2的幂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为用户提供了NumericUpDown控件,因此他可以指定纹理的大小.重要的是,此纹理具有两个大小(32、64、128 ...)的幂.

I present the user a NumericUpDown control so he can specify the size of a texture. It is important that this texture is of power of two size (32, 64, 128...).

我试图强制控件在出现ValueChanged事件时没有运气的情况下,每次单击向上或向下按钮(或按箭头键)时,仅显示此2的幂.我也尝试使用Increment属性.我一个人遇到的所有解决方案要么太笨拙,要么是特殊情况下显示了无效的值.

I have tried to force the control to present only this powers of two whenever you click the up or down buttons (or push the arrow keys) in the event ValueChanged without luck. I also have tried using the Increment property. All the solutions I have encountered by myself are either too hacky or have special case in which it shows invalid values.

是否有一种简单的方法(或者至少不是太棘手)来实现此行为?

Is there an easy way (or at least not too tricky) to achieve this behavior?

谢谢.

推荐答案

您应该继承 UpDownBase 类.

这篇关于强制NumericUpDown控件仅接受2的幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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