How to use floats with TrackBar

后端 未结 2 1539
我寻月下人不归
我寻月下人不归 2021-01-05 04:27

I\'m using a TrackBar control. By default its values are int32. I would really like to use decimal values so the use can select at a more granular

2条回答
  •  孤独总比滥情好
    2021-01-05 04:57

    You can use a multiplier. Say, for example, you wanted to make your TrackBar control go from 0 - 5 with 0.01 increments. Just set the Minimum to 0, the Maximum to 500, and increment by 1.

    When you go to set your float value, multiply it by 100, and use that for the TrackBar value.

    You should be able to get any (realistic) degree of precision in this manner, since the TrackBar works with ints, and has the full data range of Int32 available. This is much more precision than a user interface requires.

提交回复
热议问题