Let us look at a simple C# Windows Forms DomainUpDown example.
Example 1: DomainUpDown
This example will comprise the following files:
DomainUpDown.cs
Step 1: Create Project
- The first step is to create a C# Project.
- Go to
FILE-->New-->Project
to create a new project.
Step 2: Write Code
Write Code as follows:
*(a). DomainUpDown.cs
Create a file named DomainUpDown.cs
Here is the full code
using System;
using System.Windows.Forms;
namespace Examples {
class MainForm : Form {
public static void Main() {
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
public MainForm() {
Text = "DomainUpDown example";
domainUpDown1.Parent = this;
domainUpDown1.Items.AddRange(new string[] { "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10" });
domainUpDown1.Location = new System.Drawing.Point(10, 10);
domainUpDown1.TextChanged += delegate (object sender, EventArgs e) {
label1.Text = domainUpDown1.SelectedItem.ToString();
};
domainUpDown1.SelectedIndex = 1;
label1.Parent = this;
label1.Location = new System.Drawing.Point(10, 40);
}
private DomainUpDown domainUpDown1 = new DomainUpDown();
private Label label1 = new Label();
}
}
Run
Simply copy the source code into your C# Project,Build and Run. Alternatively download the code using the links provided below, then open the .csproj
project, build and run.
Reference
Download the code using the below links:
Number | Link |
---|---|
1. | Download Example |
2. | Follow code author |