MComboBox
Home
Components
MComboBox
About component
After left click, the MComboBox displays list of choices and allows user to choose one from many predefined options.
What has changed?
MComboBox is from the ground up a completely new control. Internally it uses a MListBox control so you get all benefits like scroll-bar customization, multiple item types support at once, search filter and many more.
How to use it?
Like other controls, MColorBox can be simply droped from toolbox on the form. If you are not using IDE with integrated form designer (like Visual Studio), you can always create color-box programmatically:
// Initialize combo-box first
MComboBox comboBox = new MComboBox();
// Set location
comboBox.Location = new Point(50, 50);
// Don't forget to add our newly created
// combo-box to form's control collection.
targetForm.Controls.Add(comboBox);
using System;
using System.Windows.Forms;
using Minimal.Components;
namespace Demo
{
public partial class MyForm : Form
{
// Initialize combo-box first
MComboBox comboBox = new MComboBox();
// Form constructor
public MyForm()
{
InitializeComponent();
// Set size and location
comboBox.Location = new Point(50, 50);
// Don't forget to add our newly created
// combo-box to form's control collection.
Controls.Add(comboBox);
}
}
}
Code example asumes, that targetForm variable is form where you want to have your combo-box placed. If you are working inside a class derived from System.Windows.Forms.Form, you can of course replace targetForm variable with this keyword or in latest version of C# omit form reference completely. See second example above. Default combo-box text when no item is selected can be changed using DefaultText property. Like other M-components, click-effects, theme, accent and other M-properties are also available. MComboBox can be also opened and closed by calling Open() and Close() methods.
Adding items
Items can be added using Items property. You can pass only objects derived from MItem class. Those are for example SingleLineItem or TwoLineItem.
// Creates new single line item
SingleLineItem item = new SingleLineItem("Item 1");
// Adds item to items collection - Items property
comboBox.Items.Add(item);
// Creates new two line item
TwoLineItem item = new TwoLineItem("Item 1", "This is secondary text");
// Adds item to items collection - Items property
comboBox.Items.Add(item);
Thanks to an implicit conversion between MItem and string you can pass string directly to Items.Add() method and it will be converted to single line item automatically. See example below.
// Adds new single line item to combo-box
comboBox.Items.Add("Item 1");
There are of course cases where single line or two line items do not fit your needs. In that scenario you can inherit from MItem class and design your own item. See MItem class documentation for more.
Getting selected item
Selected item can be optained using SelectedItem property. This property is of type MItem. You can get main text of item by calling SelectedItem.PrimaryText.
Search-bar
Search-bar helps user to quickly find what he is looking for. It can be enabled with DisplaySearch property. Search-bar has also a text hint which can be changed using SearchBarText.
Class content
Assembly |
Minimal.dll |
Namespace |
Minimal.Components |
Inheritance |
MBufferedPanel |
Attributes |
Minimal.Components.Design.ComboBoxDesigner |
Implements |
IMComponent |
This list doesn’t include content derived from the parent class. See MBufferedPanel documentation for a complete list of items.
Constructors
Name |
Description |
|
MComboBox() |
Initializes a new instance of the MComboBox class. |
|
Properties
Name |
Description |
Type |
Component |
Handles life-cycle of the M-Component. |
MComponent |
DefaultText |
Default text of the combo-box when no item is selected. |
string |
ClickEffect |
Click effect of the combo-box. |
ClickEffect |
Accent |
Component's accent color. Main visible color of the component. |
Color |
CustomTheme |
Component's custom theme. Will override default parent M-form or application-wide theme. |
Theme |
DisplaySearch |
True if combo-box should have search-bar. |
bool |
SearchBarText |
Hint text of the search-bar. |
string |
Fields
Name |
Description |
Type |
- |
- |
- |
Events
Name |
Description |
Type |
ClickEffectChanged |
Fires when the ClickEffect property is changed. |
PropertyChangedEventHandler |
AccentChanged |
Fires when the Accent property is changed. |
PropertyChangedEventHandler |
CustomThemeChanged |
Fires when the CustomTheme property is changed. |
PropertyChangedEventHandler |
DisplaySearchChanged |
Fires when the DisplaySearch property is changed. |
PropertyChangedEventHandler |
Methods
Name |
Description |
Returns |
Open() |
Opens combo-box |
- |
Close() |
Closes combo-box |
- |