限制数字输入vb属性网格 [英] Restrict numeric input vb property grid

查看:185
本文介绍了限制数字输入vb属性网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量,只能设置为某些数字(整数和小数),并由用户使用属性网格分配。我想要的是像Enum那样的行为,用户可以从可接受的值的下拉列表中进行选择。但是枚举不支持非整数数字输入。任何想法?

解决方案

完成取得/设置,只有在超出可接受的范围内才能更改值。

 < DataMember()> 
< DisplayName(鱼眼角度)>
<说明(此值表示鱼眼视图中使用的角度,如果启用,可接受范围为45至360度,默认值为180度。)>
< DefaultValue(180)>
公共财产FisheyeAngle As Double
获取
返回_FisheyeAngle
结束Get
Set(value As Double)
如果value< 45然后
_FisheyeAngle = 45
ElseIf value> 360然后
_FisheyeAngle = 360
Else
_FisheyeAngle = value
结束如果
结束集
结束属性


I have a variable that can only be set to certain numbers (integers and decimals) and that gets assigned by the user using a property grid. What I want is something that behaves like an Enum, where the users can select from a a drop down list of acceptable values. However enums don't see to support non integer numeric input. Any ideas?

解决方案

Ended up doing get/set and just changing the value if it's outside the acceptable range.

<DataMember()>
<DisplayName("Fisheye Angle")>
<Description("This value indicates the angle used in the fisheye view, if it is enabled.  The acceptable range is 45 to 360 degrees with 180 degrees being the default. ")>
<DefaultValue(180)>
Public Property FisheyeAngle As Double
    Get
        Return _FisheyeAngle
    End Get
    Set(value As Double)
        If value < 45 Then
            _FisheyeAngle = 45
        ElseIf value > 360 Then
            _FisheyeAngle = 360
        Else
            _FisheyeAngle = value
        End If
    End Set
End Property

这篇关于限制数字输入vb属性网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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