NumericUpDown

This offers to enter a numerical value, within a given range. The user can enter a value, out of the range.
NumericUpDown
API: System.Windows.Forms.NumericUpDown
Naming Convension: numxxxxxx

Properties of NumericUpDown
Property Description
Value Gets or sets the current value in the NumericUpDown control.
DecimalPlaces Specifies the no. of decimal places in the value
Minimum Specifies the minimum value in the range.
Maximum Specifies the maximum value in the range.
TextAlign Left / Center / Right
UpDownAlign Left / Right
Name, ReadOnly, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, BackgroundImage, BackgroundImageLayout, ContextMenuStrip, BorderStyle


Events of NumericUpDown

Event Description
ValueChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave

DomainUpDown

It is similar to combo box, but it looks like NumericUpDown.
DomainUpDown
API: System.Windows.Forms.DomainUpDown
Naming Convension: domxxxxxx

Properties of DomainUpDown

Property
Items, Sorted, Name, Text, TextAlign, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, ContextMenuStrip

Events of DomainUpDown

Event
SelectedItemChanged, TextChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Leave

Run Time Properties of DomainUpDown

Property
domObj.SelectedItem, domObj.SelectedIndex, domObj.Items.Count, domObj.Items[index], domObj.Text

Methods of DomainUpDown
Method Description>
domObj.Items.Add(“xxxxx”) Adds a new item at the end of the domainupdown items.
domObj.Items.Insert(index, “xxxx”) Inserts a new item at the specified position.
domObj.Items.RemoveAt(index) Removes an item, based on its index.
domObj.Items.Clear() Removes all the items in the domainupdown.
domObj.Items.IndexOf(“xxxx”) Searches the given string the items collection, and returns the index, if it found; otherwise, it returns -1.
domObj.Clear() Clears the text entered in the domainupdown.

Demo on NumericUpDown and DomainUpDown

Design
txtMyText
lblFont
lblSize
domFont
Items: Times New Roman, Tahoma, Arial, Arial Black, Century Gothic, Trebuchet MS, Palatino Linotype
Text: Tahoma
numSize
Value: 10
Minimum: 1
Maximum: 100

NumericUpDown

private void ChangeFont()
{
string font = Convert.ToString(domFont.SelectedItem);
int size = Convert.ToInt32(numSize.Value);
txtMyText.Font = new Font(font, size);
}

private void domFont_SelectedItemChanged(object sender, EventArgs e)
{
ChangeFont();
}

private void numSize_ValueChanged(object sender, EventArgs e)
{
ChangeFont();
}

DateTimePicker

This control enables the user, to select a date or time value at run time. When the drop down button is clicked, it displays a calendar for date selection. When you change the “Format” property, it offers to select the time also.
API: System.Windows.Forms.DateTimePicker
Naming Convension: dtPickerxxxxxx
Properties of DateTimePicker

Property Description
Value Gets or sets the current value in the control.
Format Specifies the format of the date selection. (Short / Long / Time / Custom)
CustomFormat Used to specify the customer date formats. (with words and symbols like dd, mm, yyyy, -, / etc.)
ShowUpDown Enables / Disables the “up/down” buttons in the control.
MinDate Specifies the minimum date, that can be selected at run time.
MaxDate Specifies the maximum date, that can be selected at run time.
Name, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, ContextMenuStrip

Events of DateTimePicker
Event
ValueChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave

Demo on DateTimePicker

NumericUpDown
Design
lblSelectDOB
dtPickerDOB
Format: Short
lblAgePrompt
lblAge

private void Form1_Load(object sender, EventArgs e)
{
dtPickerDOB.Value = DateTime.Now.AddYears(-20);
}
private void dtPickerDOB_ValueChanged(object sender, EventArgs e)
{
DateTime dob = dtPickerDOB.Value;
DateTime now = DateTime.Now;
if (now > dob)
{
TimeSpan ts = now - dob;
int Age = ts.Days / 365;
lblAge.Text = Age + " years.";
}
else
lblAge.Text = "Invalid DOB.";
}

MonthCalendar

Similar to DateTimePicker. It offers for a date selection. But this control, displays the calendar directly. In the calendar, the user can select any date.
Month Calendar

API: System.Windows.Forms.MonthCalendar
Naming Convension: monCalxxxxxx

Properties of MonthCalendar

Property Description
ShowToday Displays / hides today’s date at the bottom of the control.
ShowWeekNumbers Displays / hides the week no’s at left side.
MinDate Specifies the minimum date, that can be selected at run time.
MaxDate Specifies the maximum date, that can be selected at run time.
Name, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, ContextMenuStrip

Events of MonthCalendar
Event
DateChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave

Note: There is not any property, that gets the currently selected date in the calendar; so that, we have to use “DateRangeEventArgs” class object to access currently selected date value in the “DateChanged” event.

Demo on MonthCalendar
NumericUpDown
private void monCalMyDate_DateChanged(object sender, DateRangeEventArgs e)
{
lblSelectedDate.Text = "You have selected: " + e.Start.ToShortDateString();
}