ComboBoxCtl Sample: Demonstrates the Windows Forms ComboBox Control
The ComboBoxCtl sample shows how to use Windows Forms in a .NET Framework application, focusing on the functionality of combo boxes:
- Display type: simple, drop-down, and drop-down list
- Drawing mode
- Item height when the combo box is drawn as "owner draw fixed"
- Other properties, such as how many items should be displayed when the list is shown and whether the items should be sorted
Building and Running the Sample
To build and run ComboBoxCtl using Visual Studio
- In the Visual Studio IDE, open the solution file comboboxctl.sln.
- In Solution Explorer, right-click the ComboBoxCtl solution.
- On the shortcut menu, click Build.
- On the Debug menu, click Start.
The application displays two combo boxes filled with colors that control the colors in the box in the lower right corner. The aspects of these combo boxes are determined by the collection of check boxes and combo boxes found on the right. For example, by selecting the Style to "dropdown list" and the Draw mode to "owner draw fixed," the combo boxes on the left display the name of the color using the corresponding color along with a rectangle filled with the same. The implementation code for this is in
ComboBoxCtl::combo_DrawItem, which is invoked for every item when the drawing mode is owner draw.
Classes and Keywords
This sample demonstrates the following classes:
ComboBox; Panel; CheckBox; ToolTip; GroupBox; Form
This sample demonstrates the following keywords:
ComboBox::Size; ComboBox::DropDownStyle; ComboBox::DrawMode; ComboBox::TabIndex; ComboBox::Sorted; ComboBox::Text; ComboBox::Location; ComboBox::add_KeyPress; ComboBox::add_DrawItem; ComboBox::add_MeasureItem