Hi
One way is to measure each of the strings in the ListBox, keeping the largest as you iterate through and after iteration finished, set the ListBox width accordingly.
You can measure a string, with the appropriate font: below is an example. You can fine tune the width returned by adding a character or two to the string being measured to suit your needs.
' Test code
Dim r As New Random
Dim s As String = "abcdefghijklmnopqrstuvwxyz"
s &= s.ToUpper & "1234567890"
With ListBox1
For i As Integer = 0 To 19
Dim c As Integer = r.Next(5, 15)
.Items.Add(s.Substring(r.Next(0, s.Length - c), c))
Next
End With
ListBox1.Width = GetWidth()
Function GetWidth() As Integer
Dim w As Integer = 0
For Each s As String In ListBox1.Items
' the "XXX" is just extra spacing
Dim ww As Integer = TextRenderer.MeasureText(s & "XXX", ListBox1.Font).Width
If ww > w Then w = ww
Next
Return w
End Function