Results 1 to 7 of 7

Thread: Cannot control List Box Height???

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Cannot control List Box Height???

    There seems to be some problem with Run-time control of the Height of a List Box.

    lboxText.Height = X does not work for all values of X

    At least that what seems to happen. When I had a problem with an application, I made up the following Test Code.
    VB Code:
    1. Private Sub cmdHeight_Click()
    2. Dim J As Integer
    3. Dim Tally As Integer
    4.  
    5. lboxTest.Font = "MS Sans Serif"
    6. lboxTest.FontBold = True
    7. lboxTest.FontSize = 10
    8. lboxTest.Clear
    9. lboxA.Clear
    10. lboxB.Clear
    11.  
    12. Tally = -200
    13.  
    14. For J = 100 To 2000
    15.         lboxTest.Height = J
    16.         If lboxTest.Height = J Then
    17.                 lboxA.AddItem CStr(J) & " / " & CStr(lboxTest.Height)
    18.             Else
    19.                 lboxB.AddItem CStr(J) & " / " & CStr(lboxTest.Height)
    20.           End If
    21.        
    22.         'Tally = Tally + 1
    23.         'If Tally > 0 Then
    24.                 'Exit Sub
    25.             'End If
    26.     Next J
    27.        
    28. End Sub
    The above uses a Form with a Command Button (cmdHeight), and three List Boxes: lboxTest, lboxA, & lboxB. It attempts to set the Height of the Test List Box. The results of the attempts are recorded in two other List Boxes: One showing successful attempts and one showing situations for which the height was not set as specified.

    I was astonished when I ran the above and examined the contents of List Boxes A & B.

    Did I do something wrong? Am I misunderstanding something simple? Has anybody else encountered a similar situation?

    The results vary depending on the Font parameters for lboxTest.

    For my application, I wanted to change the height of a List Box depending on how many items were to be put into it. To identify each item in the List Box, I wanted to put Labels on the form to the left of the List Box.

    To do the above required precise run-time control of the height of the list Box. which does not seem to be possible.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    It snaps.

    Easiest way to explain it.

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    could it be the IntegralHeight property that is set to true and not false that causes this ?
    -= a peet post =-

  4. #4
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Height of a Listbox depends on current font height. Try using this snippet code and let me know:
    VB Code:
    1. Private Sub Form_Load()
    2. '=======================
    3. Dim i%, h%
    4.  
    5.     Me.Show
    6.     Me.Font = List1.Font
    7.     h = Me.TextHeight("A")
    8.     For i = 0 To 9
    9.         List1.AddItem "Item " & i
    10.         List1.Height = h * (i + 1)
    11.     Next i
    12.  
    13. End Sub
    Roy

  5. #5
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Note: Me.Show presents for debugging only.
    Roy

  6. #6
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Are we done with this? If yes then chage topic to "Resolved".
    Roy

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    The IntegralHeight property seems to allow fine control of List Box height, although there seems to be some minimum height which is about 25% larger the height of a text string.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width