When one sets the DropDownStyle property of a combobox control to DropDownList, the system (from windows 7 on, not sure I had this problem in Vista) changes the appearance of the field, so that it somehow reminds one of a command button.

I definitely need the DropDownList behavior, but I'd like to have a free hand in setting the backcolor. I tweaked the drawmode property, but then the values are not displayed anymore.

So is there a quick fix to this, or do I have to code the dropdownlist behaviour to work around this?

Many thanks and happy New Year.

Marc

A workable solution is here : http://stackoverflow.com/questions/3789596/combobox-appearance

The trick seems to be to set the DrawMode property to OwnerDrawFixed and then to add this method in vB.Net (translated and included straight from the link above)

        Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
            e.DrawBackground()
            If e.State = DrawItemState.Focus Then
                e.DrawFocusRectangle()
            End If
            Dim index = e.Index
            If index < 0 OrElse index >= Items.Count Then
                Return
            End If
            Dim item = Items(index)
            Dim text As String = If((item Is Nothing), "(null)", item.ToString())
            Using brush = New SolidBrush(e.ForeColor)
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
                e.Graphics.DrawString(text, e.Font, brush, e.Bounds)
            End Using
        End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.