Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21238

Resize a ListBox to can display a fixed number of items

$
0
0
Goodmorning :)

I have a ListBox that shows several items (I don't know how many they are), but I'd like that the control can display at most FIVE items per time.

I wrote this code:
Code:

Sub ResizeList()
    Const MaxItems = 6  'Consider 6 items and let IntegralHeight property to fix.
                                  'WARNING: IntegralHeight = True

    Dim Items As Long
    Items = List1.ListCont

    List1.Height = Form1.TextHeight(List1.List(0)) * IIf(Items > 5, MaxItems, Items)
End Sub

This might work but I don't think it's the best solution. In fact, what happens if both the ListBox and the Form use different fonts?

Can you tell me a more elegant solution (if exists) ?

Thanks, :wave:

Viewing all articles
Browse latest Browse all 21238

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>