Home
C#.WinForms
DomainUpDown Control Example
Updated Sep 27, 2022
Dot Net Perls
DomainUpDown. How can you present a limited selection of options? This should use only minimal screen space. In Windows Forms, you can provide a DomainUpDown control.
Up, down arrows. The DomainUpDown control has nothing to do with website domain names. Instead, it has an up and down arrow box that selects the current text item.
Example. A good place to initialize the DomainUpDown control is in the Load event of the enclosing form. Please double-click on the enclosing form to create this event.
Form
Next We add several items to the DomainUpDown control. The current item can be determined or set with the Text property.
using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Items. DomainUpDown.DomainUpDownItemCollection items = this.domainUpDown1.Items; items.Add("Dot"); items.Add("Net"); items.Add("Perls"); // Set Text. this.domainUpDown1.Text = "Dot"; } private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e) { // Run code every time the item is changed. this.Text = domainUpDown1.Text; } } }
SelectedItemChanged. Every time the selected item is changed by the user, this code is executed. We set the Text property of the Form to the current item in the DomainUpDown.
A summary. The DomainUpDown control provides an alternative to radio buttons or other pull-down lists. It can be useful in a variety of places, including preferences dialogs.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Sep 27, 2022 (rewrite).
Home
Changes
© 2007-2025 Sam Allen