Back to Devexpress

How to: Show Enumeration's Values in ImageComboBoxEdit Control

windowsforms-9491-controls-and-libraries-editors-and-simple-controls-examples-how-to-show-enumerations-values-in-imagecomboboxedit-control.md

latest2.2 KB
Original Source

How to: Show Enumeration's Values in ImageComboBoxEdit Control

  • Oct 25, 2019
  • 2 minutes to read

The following example demonstrates how to add the values of the HorzAlignment enumeration to the ImageComboBoxEdit control. When a specific item is selected from the dropdown, the corresponding alignment is applied to a text editor.

The image below shows the result of executing the code below. In the image, the ‘Center’ item is selected in the ImageComboBoxEdit control and this centers the text within a text editor:

csharp
using DevExpress.Utils;

// Add the enumerator's values as dropdown items to the ImageComboBoxEdit control.
imageComboBoxEdit1.Properties.Items.AddEnum(typeof(HorzAlignment));

// A SelectedIndexChanged event handler of the ImageComboBoxEdit control.
private void imageComboBoxEdit1_SelectedIndexChanged(object sender, System.EventArgs e) {
   var icBox = sender as ImageComboBoxEdit;
   if(icBox.SelectedIndex > 0) {
      // Get the selected item.
      ImageComboBoxItem item = icBox.SelectedItem as ImageComboBoxItem;
      // Apply the selected alignment to a text editor.
      textEdit1.Properties.Appearance.TextOptions.HAlignment = (HorzAlignment)item.Value;
   }
}
vb
Imports DevExpress.Utils

' Add the enumerator's values as dropdown items to the ImageComboBoxEdit control.
ImageComboBoxEdit1.Properties.Items.AddEnum(GetType(HorzAlignment))

' A SelectedIndexChanged event handler of the ImageComboBoxEdit control.
Private Sub ImageComboBoxEdit1_SelectedIndexChanged(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles ImageComboBoxEdit1.SelectedIndexChanged
   Dim icBox = TryCast(sender, ImageComboBoxEdit)
   If icBox.SelectedIndex > 0 Then
      ' Get the selected item.
      Dim item As ImageComboBoxItem = TryCast(icBox.SelectedItem, ImageComboBoxItem)
      ' Apply the selected alignment to a text editor.
      textEdit1.Properties.Appearance.TextOptions.HAlignment = CType(item.Value, HorzAlignment)
   End If
End Sub