Visual C#

Windows Control: The Domain Up-Down

A spin button, also called an up-down control, is usually made to display a numeric value that can then be increased or decreased when the user clicks one…

1 min read132 words1 code sample

Description#

Up-down controls, or spin buttons, are traditionally used for incrementing or decrementing numerical values. In older Windows programming, handling non-numeric data in these controls required complex workarounds. The .NET Framework simplifies this by offering the DomainUpDown control, which is specifically designed for text-based values. Just like NumericUpDown, the DomainUpDown class inherits from UpDownBase to provide its core spin-button features.

Creating a Domain Up-Down Control#

At design time, to get a domain up-down control, from the Toolbox, you can click the DomainUpDown button and click the form. To programmatically create a domain up-down control, declare a variable of type DomainUpDown, initialize it and add it to the Controls property of the container that will hold it. Here is an example:

C#
using System;
using System.Drawing;
using System.Windows.Forms;

public class Exercise : System.Windows.Forms.Form
{
    DomainUpDown spnNames;

    public Exercise()
    {
        InitializeComponent();
    }

    private void InitializeComponent()
    {
        spnNames  = new DomainUpDown();
        
        Controls.Add(spnNames);
    }
}

public class Program
{
    static int Main()
    {
        System.Windows.Forms.Application.Run(new Exercise());
        return 0;
    }
}

The resulting output is:

Home Page Copyright © 2008-2009 C# Key Next