Monday, January 6, 2020

Adjust dropdown width according to longest content (VB)

        For Each item As String In cboToResource.Items
            If TextRenderer.MeasureText(item, cboToResource.Font).Width > (cboToResource.DropDownWidth - SystemInformation.VerticalScrollBarWidth) Then
                cboToResource.DropDownWidth = TextRenderer.MeasureText(item, cboToResource.Font).Width + SystemInformation.VerticalScrollBarWidth
            End If
        Next

        cboToResource.ClientSize = New Size(cboToResource.DropDownWidth, cboToResource.ClientSize.Height)

No comments:

Post a Comment