Click here to Skip to main content
13,297,266 members (67,731 online)
Click here to Skip to main content
Add your own
alternative version


76 bookmarked
Posted 17 Aug 2005

Flat ComboBox with MS Office XP/2003 style support

, 1 Dec 2005
Rate this:
Please Sign up or sign in to vote.
An article on creating a flat combobox using VB.NET.


First of all, on the Internet, a lot of examples of flat combo boxes can be found. I tried to make a very simple one with a lot of functionality. On the screenshot above, you can see the functions that I have integrated: support for big fonts (the arrow will be centered), RTL (right to left) support, support for two dropdown styles (simple is not supported yet), and of course the two styles.

The different states

Office XP
Office 2003




'Enum with all the possible states
Enum states
End Enum
'Variable to save the current state
Dim state As states = states.normal
Function UpdateState()
    'save the current state
    Dim temp As states = state
    If Me.Enabled Then
        If Me.DroppedDown Then
            Me.state = states.dropeddown
            If ClientRectangle.Contains(_
                    PointToClient(Me.MousePosition)) Then
                Me.state = states.focused
            ElseIf Me.Focused Then
                Me.state = states.focused
                Me.state = states.normal
            End If
        End If
        Me.state = states.disabled
    End If
    'only redraw if the state has changed
    If state <> temp Then
    End If
End Function

Using the code

FlatComboBox is a UserControl based on Windows.Forms.ComboBox:

Imports System.Drawing.Drawing2D

Public Class FlatComboBox
    Inherits System.Windows.Forms.ComboBox


End Class

Reacting on events (mousemove etc.) is done by overriding WndProc:

Protected Overrides Sub WndProc(ByRef m As _
        Select Case m.Msg

            Case &HF

                '"simple" is not currently supported
                If Me.DropDownStyle = _
                           ComboBoxStyle.Simple Then Exit Sub

                '==========START DRAWING===========
                g = Me.CreateGraphics
                'clear everything
                If Me.Enabled Then
                End If
                'call the drawing functions
                '===========STOP DRAWING============

            Case 7, 8, &H7, &H8, &H200, &H2A3
                'WM_KILLFOCUS, WM_MOUSEMOVE,  
                'WM_MOUSELEAVE (if you move the mouse fast over
                'the combobox, mouseleave doesn't always react)

        End Select
    End Sub

To change the style (XP/2003), I've added a Public property:

'Property to let the user change the style
    Public Property FlatComboStyle() As styles
            Return style
        End Get
        Set(ByVal Value As styles)
            style = Value
        End Set
    End Property

Points of interest

In the combo box, there are two parts (the control itself and a kind of textbox). If the DropDownStyle is set to DropDownList, I need to draw the text manually because then there is no textbox. Because the event MouseLeave doesn't always react, a timer refreshes the control every 20 ms. Just have a look at the code and you will see how easy it is!

Thanks to


  • Bug fix: Timer will be disabled while disposing! (See reactions below for more information.)
  • First revision: Some big and small bugs are now fixed! (See reactions below for more information.)
  • Second revision: 'Function' replaced by 'Private Sub' and others, and added a VB 2005 (.NET 2.0) version of the demo.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Wouter Devinck
Web Developer
Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

NewsAdvanced list box and combo box Pin
brett5630-Nov-05 6:41
memberbrett5630-Nov-05 6:41 
GeneralRe: Advanced list box and combo box Pin
Wouter Devinck30-Nov-05 7:03
memberWouter Devinck30-Nov-05 7:03 
NewsRe: Advanced list box and combo box Pin
brett5630-Nov-05 7:26
memberbrett5630-Nov-05 7:26 
QuestionMemory Leak? Pin
JerryTanski23-Nov-05 8:07
memberJerryTanski23-Nov-05 8:07 
AnswerRe: Memory Leak? Pin
JerryTanski23-Nov-05 8:16
memberJerryTanski23-Nov-05 8:16 
GeneralRe: Memory Leak? Pin
Wouter Devinck23-Nov-05 9:45
memberWouter Devinck23-Nov-05 9:45 
GeneralRe: Memory Leak? Pin
legabertrand13-Dec-05 6:33
memberlegabertrand13-Dec-05 6:33 
GeneralRe: Memory Leak? Pin
Wouter Devinck13-Dec-05 8:06
memberWouter Devinck13-Dec-05 8:06 
QuestionFunctions? Pin
DodgerSharp14-Nov-05 6:10
memberDodgerSharp14-Nov-05 6:10 
AnswerRe: Functions? Pin
Wouter Devinck14-Nov-05 9:01
memberWouter Devinck14-Nov-05 9:01 
GeneralRe: Functions? Pin
DodgerSharp14-Nov-05 10:13
memberDodgerSharp14-Nov-05 10:13 
GeneralPermission Pin
DodgerSharp14-Nov-05 5:53
memberDodgerSharp14-Nov-05 5:53 
GeneralRe: Permission Pin
Wouter Devinck14-Nov-05 9:14
memberWouter Devinck14-Nov-05 9:14 
GeneralRe: Permission Pin
DodgerSharp14-Nov-05 10:11
memberDodgerSharp14-Nov-05 10:11 
GeneralRe: Permission Pin
Wouter Devinck15-Nov-05 7:07
memberWouter Devinck15-Nov-05 7:07 
GeneralRe: Permission Pin
DodgerSharp15-Nov-05 8:06
memberDodgerSharp15-Nov-05 8:06 
GeneralRe: Permission Pin
Wouter Devinck15-Nov-05 8:44
memberWouter Devinck15-Nov-05 8:44 
AnswerRe: Permission Pin
DodgerSharp18-Nov-05 20:56
memberDodgerSharp18-Nov-05 20:56 
GeneralNot Support DataSource Pin
wiratk13-Nov-05 17:29
memberwiratk13-Nov-05 17:29 
GeneralRe: Not Support DataSource Pin
Wouter Devinck14-Nov-05 8:54
memberWouter Devinck14-Nov-05 8:54 
GeneralGreat work, A problem with large strings Pin
SotirisF7-Nov-05 5:53
memberSotirisF7-Nov-05 5:53 
NewsRe: Great work, A problem with large strings Pin
Wouter Devinck8-Nov-05 10:03
memberWouter Devinck8-Nov-05 10:03 
GeneralRe: Great work, A problem with large strings Pin
Wouter Devinck9-Nov-05 5:58
memberWouter Devinck9-Nov-05 5:58 
GeneralRe: Great work, A problem with large strings Pin
SotirisF9-Nov-05 7:07
memberSotirisF9-Nov-05 7:07 
GeneralExcellent Pin
Anonymous18-Sep-05 19:08
sussAnonymous18-Sep-05 19:08 
NewsThanks to thecodeproject Pin
Wouter Devinck5-Sep-05 9:38
memberWouter Devinck5-Sep-05 9:38 
GeneralRe: Thanks to thecodeproject Pin
Shailesh Pachori20-Sep-05 3:26
memberShailesh Pachori20-Sep-05 3:26 
GeneralExcellent Pin
Vanco30-Aug-05 22:06
memberVanco30-Aug-05 22:06 
GeneralRe: Excellent Pin
Wouter Devinck30-Aug-05 23:34
memberWouter Devinck30-Aug-05 23:34 
GeneralRe: Excellent Pin
Vanco30-Aug-05 23:35
memberVanco30-Aug-05 23:35 
GeneralGreat job !!!!, just a little problem.. Pin
derfy7424-Aug-05 2:12
memberderfy7424-Aug-05 2:12 
GeneralRe: Great job !!!!, just a little problem.. Pin
Wouter Devinck24-Aug-05 2:40
memberWouter Devinck24-Aug-05 2:40 
GeneralRe: Great job !!!!, just a little problem.. Pin
Wouter Devinck24-Aug-05 8:35
memberWouter Devinck24-Aug-05 8:35 
GeneralGreat Pin
vbinfo18-Aug-05 22:20
membervbinfo18-Aug-05 22:20 
GeneralRe: Great Pin
Wouter Devinck18-Aug-05 23:17
memberWouter Devinck18-Aug-05 23:17 
GeneralGreat Article Pin
tENBace18-Aug-05 3:53
membertENBace18-Aug-05 3:53 
GeneralRe: Great Article Pin
Wouter Devinck18-Aug-05 23:13
memberWouter Devinck18-Aug-05 23:13 
GeneralRe: Great Article Pin
computerguru9238223-Aug-05 17:06
membercomputerguru9238223-Aug-05 17:06 
GeneralRe: Great Article Pin
Wouter Devinck3-Sep-05 10:38
memberWouter Devinck3-Sep-05 10:38 
GeneralGreat Article Pin
masukuma18-Sep-05 21:54
sussmasukuma18-Sep-05 21:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 1 Dec 2005
Article Copyright 2005 by Wouter Devinck
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid