Click here to Skip to main content
13,351,044 members (53,108 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 18 Jun 2008

Numeric UpDown Control for Hardware Control Applications or Yet Another SpinEdit

, 18 Jun 2008
Rate this:
Please Sign up or sign in to vote.
An article on numeric Up/Down control with some unique features useful for hardware control applications


For many of my projects which are mainly related to controlling hardware, I need a numeric UpDown (SpinEdit) control which could easily and quickly change value extending along many orders of magnitude, let's say to change frequency from 1 to 2 GHz and then add 200 Hz more. Unfortunately standard controls provided by Borland VCL or .ET do not satisfy this requirement. A search among third party controls was not successful too as I needed some specific capabilities, most notably the value late update. Under the late update I mean that for hardware control application it is common that SpinEdit controls value on remote device and thus it is desirable to initiate value change by SpinEdit, but postpone the actual Value change until hardware confirms that parameter has been changed.

The simple IgSpinEdit control offered in this article provides the required functionality. It was originally developed for Borland C Builder, but as I started to use .NET some time ago I ported it to C# and improved it a bit. I am not going to discuss the actual code in this article. It is present in the zip file. I will only give a brief explanation of the major properties.

Using the Code

The control is built upon UserControl and provides the following original features:

  • Extra UpDown buttons to control Increment value, which may change between adjustable IncrementMin and IncrementMax. On every Increment change, a position of the digit in the value controlled by Value UpDown is advanced back or forth on one position thus providing quick navigation along wide range numbers. Tooltip gives a clue as to which digital position is currently affected.
  • IncrementVisible property which controls whether or not Increment UpDown buttons are visible.
  • ExternalUpdate property which governs if the Value changes instantly or through external code.
  • Pow2Increment property which, if set, directs the control to generate sequence where the next value is twice as high or twice as low as the previous one. It can generate any base*2^n series, e.g. useful 1, 2, 4, 8 … n^2 (base = 1). In this mode, Increment is controlled by IgSpinEdit itself and thus Increment UpDown buttons are automatically hidden.
  • Flexible visual representation of the Value provided by FormatString property along with ValueAsInt and ValueAsHex properties. ValueAsInt and ValueAsHex do not change the internal representation of the value, which is double, but control how the value is displayed. For example, to show value as Hex, set ValueAsHex to true and FormatString to “0x{0:Xn}”, where n is the number of digits to display. ValueAsHex, if set, also changes Increment multiplier from default 10 to 16 to provide same one digit advance on every hit on Increment UpDown.
  • ValueChanging event which is raised if ExternalUpdate is set to true and value UpDown button has been pressed. The control passes a new value to the handler without updating its internal state. Handler may cancel update by setting e.Cancel or pass new e.Value to external code which should later update internal value state by assigning to Value property directly.
  • ValueChanged event which is raised when Value has been updated internally.

Other properties and events are inherited from UserControl.

The control does not try to prevent all possible erroneous parameter combinations, so please apply common sense while setting control properties and it will work quite well.

The control is accompanied with a simple test application showing how to use the control and allows playing with parameters. The application screenshot is presented at the beginning of the article.

One important thing to note is that IgSpinEdit implements ISupportInitialize interface to handle correct initialization. Fortunately VS Designer automatically handles calls to ISupportInitialize BeginInit()/EndInit() pair, so you should not do it yourself.

For test convenience, an "External update" handler is implemented in the lower left corner of the test application and it handles ValueChanging event of all IgSpinEdit controls. Please note that on application start up, only “Value as Int” has ExternalUpdate set that prevents it from changing value until the Update button is pressed.


This article presents an extended numeric UpDown control which is especially useful for hardware control applications. There is nothing fancy in it, but I found it really useful for my projects. I hope some readers will agree with me.

Feel free to use the provided code in any way you wish. Comments and suggestions are welcome.


</li />
  • 06-18-2008: Original article


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Igor Voynovsky
Software Developer (Senior)
New Zealand New Zealand
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
urinspiration17-Jul-10 7:22
memberurinspiration17-Jul-10 7:22 
GeneralVery Nice! Pin
cj_delgross23-Oct-09 10:42
membercj_delgross23-Oct-09 10:42 
GeneralQuestion Pin
smesser12-May-09 6:04
membersmesser12-May-09 6:04 
Thanks for this control is solved a big problem for me.

I was wondering what has to be done make the control accept manually entered text?

GeneralRe: Question Pin
Igor Voynovskyy12-May-09 18:55
memberIgor Voynovskyy12-May-09 18:55 
GeneralRe: Question Pin
smesser13-May-09 4:42
membersmesser13-May-09 4:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 18 Jun 2008
Article Copyright 2008 by Igor Voynovsky
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid