georg Posted July 8, 2003 Posted July 8, 2003 Hi All, I'm 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 Quote
Cassio Posted July 8, 2003 Posted July 8, 2003 Try this 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 Quote Stream of Consciousness (My blog)
*Experts* Volte Posted July 8, 2003 *Experts* Posted July 8, 2003 To make decent multicolumn combo boxes, you'll need to OwnerDraw the items (set the DrawMode to OwnerDrawFixed). You'll 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.