0

I am programming an instrument controller in which the user needs to be able to enter values for particular instrument parameters. One such parameter is Number of Samples. I need to restrict user input according to specified a min, max, and increment:

Min: 32
Inc: 32
Max: 2097120

Therefore, the possible values it can be are:

32, 64, 96, 128, 160, ..., 2097120

I've contemplated using a ComboBox, but with this many items it will not only be slow to load the list, but it will be frustrating for the user to select a value among such a large list.

I've also thought about using a NumericUpDown, but the Increment parameter only controls the increment applied when pressing the up or down arrows. The value of the control doesn't coerce to the specified increment. For example, if I type in 38, it should coerce to the nearest possible value, which is 32. If I type in 58, it should coerce to 64.

Is there a control that would allow me to do what I want? Or would I have to inherit from NumericUpDown and handle the value changed event to coerce the value? Maybe there's a special ComboBox implementation that only loads part of the list and continues to load the rest as the user scrolls, so they don't have to wait how ever long for the entire list to load?

Thanks.

Edit: I'm going with extending the NumericUpDown class to provide what I want. Thanks for the help!

StrangerLoop
  • 39
  • 1
  • 4
  • 1
    Why don't you implement your own? – Ash Burlaczenko Mar 18 '13 at 20:52
  • 1
    maybe a trackbar? http://msdn.microsoft.com/en-us/library/system.windows.forms.trackbar.aspx – Felice Pollano Mar 18 '13 at 20:52
  • @AshBurlaczenko I wanted to see if there was some property or control I haven't found that would allow me to do this first before I went and implemented my own. I understand this is easy enough, but I don't want to do the work if I don't have to ;) – StrangerLoop Mar 18 '13 at 20:54
  • Your best bet (judging for your comments on the other answer is to extend numericupdown control. –  Mar 18 '13 at 21:01

2 Answers2

0

You could try using a TrackBar control.

You can specify the step size and the range.

But you will have 64K individial steps. A user will not be able to select that accurately. You could have two sliders, one for coarse control and one for fine control.

Or you could just let them type the number, then divide it by 32 and then multiply it by 32.

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
  • This would work, but my plan is to have this control in a DataGridViewCell, and I feel it would look awkward. – StrangerLoop Mar 18 '13 at 20:57
  • It's going to be very awkward for a user to select one value from 64K values via anything other than typing or a coarse/fine control pair. – Matthew Watson Mar 18 '13 at 20:59
  • I agree. I think I'll just have to implement my own NumericUpDown control that coerces to an increment value. Shouldn't be hard :) – StrangerLoop Mar 18 '13 at 21:01
0

As @FelicePollano suggested, a trackbar sounds like it would be the thing you want. You could ever create a trackbar to keep up with the actual values but make it invisible, then allow users to interact with it via buttons (or whatever else you want) that simply increment the value of the trackbar by its small or large incrememnt property.

Weston Odom
  • 311
  • 1
  • 6
  • 17