Input for WinForms | ComponentOne
Appearance and Styling / ComboBox
In This Topic
    ComboBox
    In This Topic

    Input provides various properties for customizing the appearance and styling Input ComboBox, so that you can generate the control as per your requirement and change the look and feel of the application you are creating.

    Appearance

    You can add any icon, image or different font styles for text, and even change the alignment of image or text as per your need. You can also alter the width of the dropdown form in ComboBox using the DropDownWidth property of the C1DropDownControlBase class.

    The following code snippet shows how to add an icon to the CheckBox control using the Icon property by using the C1BitmapIcon class, change font settings and increase the dropdown form width:

    C#
    Copy Code
    // Enhancing the appearance of ComboBox control
    comboBox.Cursor = System.Windows.Forms.Cursors.Hand;
    comboBox.DropDownWidth = 250;
    comboBox.Font = new System.Drawing.Font("Monotype Corsiva", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
    comboBox.ForeColor = System.Drawing.Color.RoyalBlue;
    comboBox.Icon = new C1.Framework.C1BitmapIcon(null, new System.Drawing.Size(16, 16), System.Drawing.Color.Transparent, Image.FromFile(@"Resources\16x16-icon-45607.png"));
    // Adding items to ComboBox
    ComboBoxItem comboBoxItem1 = new ComboBoxItem();
    ComboBoxItem comboBoxItem2 = new ComboBoxItem();
    ComboBoxItem comboBoxItem3 = new ComboBoxItem();
    ComboBoxItem comboBoxItem4 = new ComboBoxItem();
    ComboBoxItem comboBoxItem5 = new ComboBoxItem();
    ComboBoxItem comboBoxItem6 = new ComboBoxItem();
    ComboBoxItem comboBoxItem7 = new ComboBoxItem();
    ComboBoxItem comboBoxItem8 = new ComboBoxItem();
    ComboBoxItem comboBoxItem9 = new ComboBoxItem();
    ComboBoxItem comboBoxItem10 = new ComboBoxItem();
    ComboBoxItem comboBoxItem11 = new ComboBoxItem();
    ComboBoxItem comboBoxItem12 = new ComboBoxItem();
    ComboBoxItem comboBoxItem13 = new ComboBoxItem();
    ComboBoxItem comboBoxItem14 = new ComboBoxItem();
    ComboBoxItem comboBoxItem15 = new ComboBoxItem();
    ComboBoxItem comboBoxItem16 = new ComboBoxItem();
    ComboBoxItem comboBoxItem17 = new ComboBoxItem();
    ComboBoxItem comboBoxItem18 = new ComboBoxItem();
    ComboBoxItem comboBoxItem19 = new ComboBoxItem();
    ComboBoxItem comboBoxItem20 = new ComboBoxItem();
    ComboBoxItem comboBoxItem21 = new ComboBoxItem();
    ComboBoxItem comboBoxItem22 = new ComboBoxItem();
    comboBoxItem1.DisplayText = "1tem1";
    comboBoxItem2.DisplayText = "Item2";
    comboBoxItem3.DisplayText = "Item3";
    comboBoxItem4.DisplayText = "Item4";
    comboBoxItem5.DisplayText = "Item5";
    comboBoxItem6.DisplayText = "Item6";
    comboBoxItem7.DisplayText = "Item7";
    comboBoxItem8.DisplayText = "Item8";
    comboBoxItem9.DisplayText = "Item9";
    comboBoxItem10.DisplayText = "Item10";
    comboBoxItem11.DisplayText = "Item11";
    comboBoxItem12.DisplayText = "Item12";
    comboBoxItem13.DisplayText = "Item13";
    comboBoxItem14.DisplayText = "Item14";
    comboBoxItem15.DisplayText = "Item15";
    comboBoxItem16.DisplayText = "Item16";
    comboBoxItem17.DisplayText = "Item17";
    comboBoxItem18.DisplayText = "Item18";
    comboBoxItem19.DisplayText = "Item19";
    comboBoxItem20.DisplayText = "Item20";
    comboBoxItem21.DisplayText = "Item21";
    comboBoxItem22.DisplayText = "Item22";
    comboBox.Items.Add(comboBoxItem1);
    comboBox.Items.Add(comboBoxItem2);
    comboBox.Items.Add(comboBoxItem3);
    comboBox.Items.Add(comboBoxItem4);
    comboBox.Items.Add(comboBoxItem5);
    comboBox.Items.Add(comboBoxItem6);
    comboBox.Items.Add(comboBoxItem7);
    comboBox.Items.Add(comboBoxItem8);
    comboBox.Items.Add(comboBoxItem9);
    comboBox.Items.Add(comboBoxItem10);
    comboBox.Items.Add(comboBoxItem11);
    comboBox.Items.Add(comboBoxItem12);
    comboBox.Items.Add(comboBoxItem13);
    comboBox.Items.Add(comboBoxItem14);
    comboBox.Items.Add(comboBoxItem15);
    comboBox.Items.Add(comboBoxItem16);
    comboBox.Items.Add(comboBoxItem17);
    comboBox.Items.Add(comboBoxItem18);
    comboBox.Items.Add(comboBoxItem19);
    comboBox.Items.Add(comboBoxItem20);
    comboBox.Items.Add(comboBoxItem21);
    comboBox.Items.Add(comboBoxItem22);
    

    Styling

    C1ComboBox control lets you style the border, button, dropdown form, items, and much more.  The C1ComboBox class provides the BackColor and ForeColor properties to set the background and foreground colors, respectively. Besides these, it also provides the Styles property to apply styling to different states of combobox such as Default, Disabled, Hot, HotPressed, and Pressed.

    The following image showcases styling applied to the ComboBox control.

    The following code snippet shows how to set the styling properties in the ComboBox control. Here, we set the background color, foreground color, borders, and font style of the ComboBox control.

    C#
    Copy Code
    // Styling the ComboBox control
    c1ComboBox1.BackColor = System.Drawing.Color.Bisque;
    c1ComboBox1.ForeColor = System.Drawing.Color.Black;
    //Set borders 
    c1ComboBox1.Styles.Border = new C1.Framework.Thickness(2, 2, 2, 2);
    c1ComboBox1.Styles.Default.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
    c1ComboBox1.Styles.Hot.BackColor = System.Drawing.SystemColors.GradientActiveCaption;
    //Set font style
    c1ComboBox1.Font = new System.Drawing.Font("Pristina", 11F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
    //Style combobox elements
    c1ComboBox1.Styles.Button.Default.BackColor = System.Drawing.Color.Tan;            
    c1ComboBox1.Styles.DropDown.BackColor = System.Drawing.Color.LightCyan;
    c1ComboBox1.Styles.DropDown.BorderColor = System.Drawing.SystemColors.Highlight;
    c1ComboBox1.Styles.Item.Default.BackColor = System.Drawing.Color.LightCyan;
    c1ComboBox1.Styles.Item.Default.BorderColor = System.Drawing.Color.Gray;
    c1ComboBox1.Styles.Item.Hot.BackColor = System.Drawing.Color.OrangeRed;