-->

Thursday, June 6, 2013

How to use NumericUpDown controls as a Time Control in c#

How to use NumericUpDown controls as a Time Control in c#

NumericUpDown control is used when user want some numeric values as input or to show some numeric values to user. It has some properties which are mostly used about this control are:

  • Incrementthis property indicates amount to increment or decrements on each button click.
  • Minimumindicates minimum value for this control.
  • Maximumindicates maximum value for this control.
  • Valueindicates current value of this control.

Most often NumericUpDown control in windows form displays a single numeric value that can be incremented and decremented by clicking up and down buttons on the control.

We can extend this control so that user can enter time using NumericUpDown.
To do this we use two NumericUpDown control in our form, one for inserting hour and one for minutes.

In our Form1.cs (Designer file) drag and drop two NumericUpDown controls and a button from ToolBox. Button will used to show the selected time through its click event.
Now for first NumericUpDown control set
  • Increment  = 1
  • Minimum = 1
  • Maximum = 24
  • Value = 1
And for second NumericUpDown control
  • Increment  = 1
  • Minimum = 1
  • Maximum = 24
  • Value = 1
In click event of button write following code:
numeric updown control
when we run our project and set some values in both numericUpDown control and click on button it will show a message box like:
numeric updown window
Finally we have used these controls as time control.
Download source code.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved