NumericUpDown

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
Exam Prep. Guides
70-505 Study Guide
70-526 Study Guide

1. Forms Controls

2. Integrating Data
3. Printing/Reporting
4. Enhancing Usability
5. Asynchronous Prog.
6. Forms Controls
7. Configure/Deploy

edit
Exam 70-526 Preparation Guide: Configure the layout and functionality of a Windows Form to display a list of items


Contents


A NumericUpDown control is a simple way to give the user a way to select a number that falls between a minimum and a maximum value. The numeric value can be incremented or decremented by clicking the up or down buttons of the control. The user can also enter in a value.

Image:526-106.jpg


The NumericUpDown control is controlled by four integer properties: Minimum, Maximum, Value, and Increment. The Minimum and Maximum properties define the minimum and maximum values of the control. The Value property is the current value of the control. The Increment property defines the amount by which the current value is incremented or decremented when the user clicks the up or down arrow buttons. The current value is always incremented or decremented by the Increment value, unless the resulting value would be out of the range defined by the Minimum and Maximum values.


Inheritance hierarchy

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.Control
        System.Windows.Forms.ScrollableControl
          System.Windows.Forms.ContainerControl
            System.Windows.Forms.UpDownBase
              System.Windows.Forms.NumericUpDown


Useful properties

  • DecimalPlaces - Indicates the number of decimal places to display.
  • Hexadecimal - Indicates whether the value is displayed in hexadecimal format. Default value is false.
  • Increment - Indicates the value to increment or decrement the displayed value when the up or down buttons are clicked.
  • Maximum - Indicates the maximum value allowed.
  • Minimum - Indicates the minimum value allowed.
  • ThousandsSeparator - Indicates whether a thousands separator is displayed when appropriate. Default value is false.
  • Value - Indicates the value displayed.


Adding a NumericUpDown manually

Consider adding a NumericUpDown that allows all off the values for a byte to be chosen. So the range of the control will be 0x00 to 0xFF. The code to do this would be similar in nature to this example:

public void AddNumericUpDown()
{
  NumericUpDown numUpDn = new NumericUpDown();
  numUpDn.Location = new Point(50, 50);
  numUpDn.Size = new Size(100, 25);
  
  numUpDn.Hexadecimal = true;
  numUpDn.Minimum = 0;
  numUpDn.Maximum = 255;
  numUpDn.Value = 0xFF;
  numUpDn.Increment = 1;
 
  Controls.Add(numUpDn);
}


ValueChanged Event

The crucial event behind the NumericUpDown control is the ValueChanged event.

For the ValueChanged event to occur, the Value property can be changed in code, by clicking the up or down button, or by the user entering a new value that is read by the control. The new value is read when the user hits the ENTER key or navigates away from the control. If the user enters a new value and then clicks the up or down button, the ValueChanged event will occur twice.


MSDN references


Previous_Page_.gif Next_Page_.gif
© 2007-2008 Mike Kitchen

Personal tools