Fake Multi Column ComboBox

georg

Active member
Joined
Jun 26, 2003
Messages
28
Location
Australia
Hi All,

Im trying to do a fake multi column combo box, but the irregular width of characters is making things a bit messy.

Is there any way to measure the width of the font and then put some padding in my concatenated strings to even the columns up?

georg
 
Try this

Code:
Dim g As Graphics
        g = Me.CreateGraphics
        Dim myfont As New Font("Courier New", 11.25, FontStyle.Regular, GraphicsUnit.Pixel)
         StrWidth = g.MeasureString("Any String", myfonte).Width
         g.Dispose
 
To make decent multicolumn combo boxes, youll need to OwnerDraw the items (set the DrawMode to OwnerDrawFixed). Youll also need to create a custom class or structure in which you can put more than one column into.

You can then use the method Cassio mentioned to get the widths of each item (in the MeasureItem handler) and draw the text of the items and their subitems accordingly, and in the correct spot.

The reason this is necessary is because when owner drawing, you can position the text of the items absolutely; meaning, at any pixel location within the item boundaries. Without ownerdrawing, you need to rely on the size of spaces, which is not reliable at all, so you will never get a perfectly aligned column.

Search for owner-drawn objects in your MSDN to get information on ownerdrawing objects.
 
Back
Top