In Windows Forms, the ComboBox control combines the features of a TextBox and a ListBox. It displays one item at a time, with additional items accessible through a drop-down menu. The ComboBox class is part of the System.Windows.Forms namespace.
Ways to Create a ComboBox In Windows Forms
There are mainly two ways to create a ComboBox in Windows forms which are mentioned below.
- Drag and drop (Design-Time)
- Custom ComboBox (Run-Time)
Drag and drop (Design-Time)
This is the easiest way to create a ComboBox in Windows Forms using Visual Studio we just have to open the toolbox and drag and drop the button on the form in the designer and further we can change the appearance of the ComboBox using the properties. Follow these steps to create a ComboBox.
Step 1: Now locate the project with the name here we are using the default name which is Form1 and it will open a form in the editor that we can further modify.

In the image, we have two files that are open one Design and there is Form1.cs these two play a major role. We use the Form1.cs file for custom logic.
Step 2: Now open a Toolbox go to the view > Toolbox or ctrl + alt + x.

Step 3. Now open the common controls and drag and drop the ComboBox on the form where we want to it be placed.
Step 4. Now open the properties of the button press right-click on the ComboBox and it will open the properties solution explorer now we can change the appearance and the behaviour of the button.
Step 5: In the properties, we can make different types of changes we can add the items in the list which is available at the left-most bottom in the properties as shown in the image
It will open the new box (String Collection Editor ) here we can add a different list and each line is a separate list as shown in the image after adding the list click on the OK button.
Output:
Custom ComboBox (Run Time)
In this method, we are going to modify the Form1.cs file and add custom code modification in C# with the help of the ComboBox class. The following steps show how to create a ComboBox dynamically:
Step 1: Create a ComboBox using the ComboBox() constructor provided by the ComboBox class.
// Creating ComboBox
ComboBox MyComboBox = new ComboBox();
Step 2: After creating ComboBox, set the properties of the ComboBox provided by the ComboBox class.
// Set the location of the ComboBox
mybox.Location = new Point(327, 77);
// Set the size of the ComboBox
mybox.Size = new Size(216, 26);
// Add items to the ComboBox
mybox.Items.Add("C#");
mybox.Items.Add("Java");
mybox.Items.Add("Scala");
mybox.Items.Add("C");
mybox.Items.Add("C++");
Step 3: And last add this ComboBox control to form using Add() method.
// Add this ComboBox to the form
this.Controls.Add(mybox);
Step 4: Now double-click on the form in Design and it will open the Form1.cs file where code is written in C#. Here the program file is Form 1.cs Now write this code in Form1.cs file
Form1.cs file:
C#
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Creating and setting the properties of the label
Label l = new Label
{
Location = new Point(122, 80),
AutoSize = true,
Text = "Select Programming Language"
};
// Creating and setting the properties of the ComboBox
ComboBox mybox = new ComboBox
{
Location = new Point(327, 77),
Size = new Size(216, 26)
};
// Adding items to the ComboBox
mybox.Items.AddRange(new object[] { "C#", "Java", "Scala", "C", "C++" });
// Adding controls to the form
this.Controls.Add(l);
this.Controls.Add(mybox);
}
}
}
Output:
Properties
Property | Description |
---|
BackColor | This property is used to set the background colour for the ComboBox control. |
---|
DropDownHeight | This property is used to set the height in pixels of the drop-down portion of the ComboBox control. |
---|
DropDownStyle | This property is used to set a value specifying the style of the ComboBox control. |
---|
DropDownWidth | This property is used to set the width of the drop-down portion of a ComboBox control. |
---|
Font | This property is used to set the font of the text displayed by the ComboBox control. |
---|
ForeColor | This property is used to set the foreground colour of the ComboBox control. |
---|
Height | This property is used to set the height of the ComboBox control. |
---|
Items | This property is used to get an object representing the collection of the items contained in this ComboBox control. |
---|
MaxDropDownItems | This property is used to set the maximum number of items to be shown in the drop-down portion of the ComboBox control. |
---|
MaxLength | This property is used to set the number of characters a user can type into the ComboBox control. |
---|
Name | This property is used to set the name of the ComboBox control. |
---|
SelectedItem | This property is used to set the currently selected item in the ComboBox. |
---|
Size | This property is used to set the height and width of the ComboBox control. |
---|
Sorted | This property is used to set a value indicating whether the items in the combo box are sorted. |
---|
Text | This property is used to set the text associated with this ComboBox control. |
---|
Visible | This property is used to set a value indicating whether the control and all its child controls are displayed. |
---|
Events
Event | Description |
---|
Click | This event occurs when the ComboBox control is clicked. |
---|
DragDrop | This event occurs when a drag-and-drop operation is completed. |
---|
DropDown | This even occurs when the drop-down portion of a ComboBox is shown. |
---|
DropDownClosed | This event occurs when the drop-down portion of the ComboBox is no longer visible. |
---|
DropDownStyleChanged | This occurs when the DropDownStyle property has changed. |
---|
Leave | This occurs when the input focus leaves the ComboBox control. |
---|
MouseClick | This occurs when the ComboBox control is clicked by the mouse. |
---|
MouseDoubleClick | This occurs when the ComboBox control is double-clicked by the mouse. |
---|
MouseDown | This event occurs when the mouse pointer is over the ComboBox control and a mouse button is pressed. |
---|
MouseEnter | This event occurs when the mouse pointer enters the ComboBox control. |
---|
MouseHover | This event occurs when the mouse pointer rests on the ComboBox control. |
---|
SelectedIndexChanged | This event occurs when the SelectedIndex property has changed. |
---|
Similar Reads
How to set Text in ComboBox in C#?
In Windows Forms, ComboBox provides two different features in a single control, it means ComboBox works as both TextBox and ListBox. In ComboBox, only one item is displayed at a time and the rest of the items are present in the drop-down menu. You are allowed to add text in your ComboBox by using th
3 min read
How to Add Items in ComboBox in C#?
In Windows forms, ComboBox provides two different features in a single control, it means ComboBox works as both TextBox and ListBox. In ComboBox, only one item is displayed at a time and the rest of the items are present in the drop-down menu. You are allowed to a list or collection of elements in y
3 min read
Collections in C#
.math-table { border-collapse: collapse; width: 100%; } .math-table td { border: 1px solid #5fb962; text-align: left !important; padding: 8px; } .math-table th { border: 1px solid #5fb962; padding: 8px; } .math-table tr>th{ background-color: #c6ebd9; vertical-align: middle; } .math-table tr:nth-c
5 min read
How to set Name of the ComboBox in C#?
In Windows forms, ComboBox provides two different features in a single control, it means ComboBox works as both TextBox and ListBox. In ComboBox, only one item is displayed at a time and the rest of the items are present in the drop-down menu. You are allowed to provide a name to your ComboBox by us
3 min read
How to set the Size of the ComboBox in C#?
In Windows forms, ComboBox provides two different features in a single control, it means ComboBox works as both TextBox and ListBox. In ComboBox, only one item is displayed at a time and the rest of the items are present in the drop-down menu. You are allowed to set the size to your ComboBox by usin
3 min read
C# | GroupBox Class
In Windows Forms, GroupBox is a container that contains multiple controls, and the controls are related to each other. In other words, GroupBox is a frame display around a group of controls with a suitable optional title. A GroupBox in C# is used to categorize the related controls in a group. The Gr
7 min read
How to set the Location of the ComboBox in C#?
In Windows Forms, ComboBox provides two different features in a single control, it means ComboBox works as both TextBox and ListBox. In ComboBox, only one item is displayed at a time and the rest of the items are present in the drop-down menu. You are allowed to set the location of your ComboBox in
3 min read
How to Sort the Elements of the ComboBox in C#?
In Windows forms, ComboBox provides two different features in a single control, it means ComboBox works as both TextBox and ListBox. In ComboBox, only one item is displayed at a time and the rest of the items are present in the drop-down menu. You are allowed to sort the elements present in the Comb
3 min read
How to Compare Strings in C#?
A string is a collection of characters and is used to store plain text. Unlike C or C++, a string in C# is not terminated with a null character. The maximum size of a string object depends on the internal architecture of the system. A variable declared followed by "string" is actually an object of s
13 min read
How to set the Visibility of the ComboBox in C#?
In Windows forms, ComboBox provides two different features in a single control, it means ComboBox works as both TextBox and ListBox. In ComboBox, only one item is displayed at a time and the rest of the items are present in the drop-down menu. You are allowed to set the visibility of the ComboBox by
3 min read