Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
Mango TV
https://rjcodeadvance.com/custom-combobox-icon-back-text-border-color-winform-c/ 1/13
7/22/2021 Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
Hello, in this tutorial we will create a custom ComboBox with a very elegant, flat, modern
look and keeping all the basic and important functionality of a traditional ComboBox.
For example, a ComboBox with the DropDownList style allows the drop-down list to be
opened by clicking anywhere in the control, and the list can be filtered according to the
alphanumeric key that is pressed.
On the other hand, a ComboBox with the DropDown style only allows opening the drop-down
list from the icon, and being able to write freely on the control, as if it were a text box. This
is very useful for an advanced filter, autocomplete and suggesting some element of the list
according to the written word.
Regarding the appearance, you can change the color of the background, border, icon, text
and the drop-down list, change the border size and the size of the control at will.
Well, doing so will be a bit more complicated than previous custom controls, not because it is
difficult, but because it takes a little more time to re-implement all the essential
functionalities of a traditional ComboBox. So let's start with the tutorial:
// Items
private ComboBox cmbList;
private Label lblText;
private Button btnIcon;
// Events
public event EventHandler OnSelectedIndexChanged ; // Default event
public RJComboBox ()
{
cmbList = new ComboBox () ;
lblText = new Label () ;
btnIcon = new Button () ;
this . SuspendLayout () ;
// Button: Icon
btnIcon. Dock = DockStyle. Right ;
btnIcon. FlatStyle = FlatStyle. Flat ;
btnIcon. FlatAppearance . BorderSize = 0 ;
btnIcon. BackColor = backColor;
btnIcon. Size = new Size ( 30 , 30 ) ;
btnIcon. Cursor = Cursors. Hand ;
btnIcon. Click + = new EventHandler ( Icon_Click ) ; // Open dropdown
btnIcon. Paint + = new PaintEventHandler ( Icon_Paint ) ; // Draw ico
// Label: Text
lblText. Dock = DockStyle. Fill ;
lblText. AutoSize = false ;
lblText. BackColor = backColor;
lblText. TextAlign = ContentAlignment. MiddleLeft ;
lblText. Padding = new Padding ( 8 , 0 , 0 , 0 ) ;
lblText. Font = new Font ( this . Font . Name , 10F ) ;
// -> Attach label events to user control event
lblText. Click + = new EventHandler ( Surface_Click ) ; // Select com
lblText. MouseEnter + = new EventHandler ( Surface_MouseEnter ) ;
lblText. MouseLeave + = new EventHandler ( Surface_MouseLeave ) ;
// User Control
this . Controls . Add ( lblText ) ; // 2
this . Controls . Add ( btnIcon ) ; // 1
this . Controls . Add ( cmbList ) ; // 0
this . MinimumSize = new Size ( 200 , 30 ) ;
this . Size = new Size ( 200 , 30 ) ;
this . ForeColor = Color. DimGray ;
this . Padding = new Padding ( borderSize ) ; // Border Size
this . Font = new Font ( this . Font . Name , 10F ) ;
base . BackColor = borderColor; // Border Color
this . ResumeLayout () ;
AdjustComboBoxDimensions () ;
https://rjcodeadvance.com/custom-combobox-icon-back-text-border-color-winform-c/ 3/13
7/22/2021 Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
https://rjcodeadvance.com/custom-combobox-icon-back-text-border-color-winform-c/ 5/13
7/22/2021 Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
}
}
https://rjcodeadvance.com/custom-combobox-icon-back-text-border-color-winform-c/ 8/13
7/22/2021 Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
[ Browsable ( false )]
[ DesignerSerializationVisibility ( DesignerSerializationVisibility. Hidd
public object SelectedItem
{
get { return cmbList. SelectedItem ; }
set { cmbList. SelectedItem = value ; }
}
// :::: +
downloads
SEE FULL CODE (GITHUB)
Leave a reply
Your email address will not be published. Required fields are marked with *
https://rjcodeadvance.com/custom-combobox-icon-back-text-border-color-winform-c/ 10/13
7/22/2021 Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
Commentary
Name *
E-mail *
Web
Welcome to blog
Look for …
Follow me
https://rjcodeadvance.com/custom-combobox-icon-back-text-border-color-winform-c/ 11/13
7/22/2021 Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
Category:
.NET
ASP .NET
C#
Mistakes
F#
Visual basic
Windows Forms
Layered Architecture
Database
MySQL
SQL Server
Custom controls
courses
.NET (Course)
Create .Net Installer
Full Login C #, VB, SQL Server
Software Patterns (Course)
OOP (Course)
Desk
GUI
Software Patterns
OOP
Uncategorized
Web
Recent logins
Circular Picture Box - Border Gradient color + Styles - C # & WinForms
Custom ProgressBar - WinForms & C #
Custom TextBox Full - Rounded & Placeholder - WinForm, C #
Custom ComboBox - Icon, Back, Text & Border Color - WinForm C #
https://rjcodeadvance.com/custom-combobox-icon-back-text-border-color-winform-c/ 12/13
7/22/2021 Custom ComboBox - Icon, Back, Text & Border Color - WinForm C # - RJ Code Advance
Recent comments
gustavo on Custom Button - Custom controls WinForm C #
_Nooker in Modern Form + Font Awesome Icons, WinForm, C # - VB.NET
https://rjcodeadvance.com/custom-combobox-icon-back-text-border-color-winform-c/ 13/13