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.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.VB Code:
Private Sub cmdHeight_Click() Dim J As Integer Dim Tally As Integer lboxTest.Font = "MS Sans Serif" lboxTest.FontBold = True lboxTest.FontSize = 10 lboxTest.Clear lboxA.Clear lboxB.Clear Tally = -200 For J = 100 To 2000 lboxTest.Height = J If lboxTest.Height = J Then lboxA.AddItem CStr(J) & " / " & CStr(lboxTest.Height) Else lboxB.AddItem CStr(J) & " / " & CStr(lboxTest.Height) End If 'Tally = Tally + 1 'If Tally > 0 Then 'Exit Sub 'End If Next J End Sub
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.




Reply With Quote