[PROGRAMACIÓN] CAMBIAR ANCHO DROPDOWN LIST SEGÚN LARGO DEL TEXTO
Posted by Robin.Jeremy en octubre 10, 2012
Tal vez a más de alguno le ha pasado que desea cambiar el ancho solo de la lista desplegable pero no del control en si. Bueno acá les dejo el código de como hacerlo:
Private Sub SizeCombo(ByVal comboToSize As ComboBox, ByVal maxStringWidth As Integer)
Dim MyGraphics As System.Drawing.Graphics = Me.CreateGraphics
Dim StringSize As Integer
For Each ItemValue As String In comboToSize.Items
StringSize = CInt(MyGraphics.MeasureString(ItemValue, comboToSize.Font, maxStringWidth).Width) + 1
If comboToSize.DropDownWidth <; StringSize Then
comboToSize.DropDownWidth = StringSize
End If
Next
End Sub
Deja un comentario