![]() |
Windows Control: The Combo Box |
|
Description |
|
A combo box is a list of items that the user can select from. Like a list box, a combo box is usually made of a list of strings. Unlike a list box, a combo box saves space by using just as much room as a text box control. To show that it is holding a list, a combo box displays a down-pointing arrow on the right side of its text box. In the following screenshot, the Font Effects property page of the Character dialog box of OpenOffice.org presents the Underlining, the Color, the Effects, the Strikethrough, the Relief, and the Font Color combo boxes: |
![]() Because a combo box does not (permanently) display its list like a list box, to show its content, the user can click the arrow button. Here is an example:
To support combo boxes, the .NET Framework provides a class named ComboBox.
At design time, to add a combo box to your application, from the Common
Controls section of the Toolbox, you can click the ComboBox button
using System;
using System.Drawing;
using System.Windows.Forms;
public class Exercise : System.Windows.Forms.Form
{
Label lblTitle;
ComboBox cbxAcademicDisciplines;
public Exercise()
{
InitializeComponent();
}
private void InitializeComponent()
{
lblTitle = new Label();
lblTitle.Text = "Academic Disciplines";
lblTitle.Location = new Point(12, 12);
lblTitle.AutoSize = true;
Controls.Add(lblTitle);
cbxAcademicDisciplines = new ComboBox();
cbxAcademicDisciplines.Location = new Point(12, 32);
Controls.Add(cbxAcademicDisciplines);
}
}
public class Program
{
static int Main()
{
System.Windows.Forms.Application.Run(new Exercise());
return 0;
}
}
This would produce:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||
| Home | Copyright © 2007-2012 FunctionX | Next |
|
|
||