Not a Member Yet,
Click here to Register
How do you like the new design?
It's cool, great job
[tally: 70%] 70%
It's okay
[tally: 20%] 20%
Its OK but I liked the old layout better
[tally: 0%] 0%
Please bring the old one back
[tally: 10%] 10%

votes: 10

ID: 270
Viewed: 2244
Added: Jul 26, 2002
Snippet uploaded by: snippet
Written By: Randy Birch
Demo: Sorry, no demo

User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Set Dropped Width

Highlight all by clicking in box

Highlight All
' From a Use-Net posting by Randy Birch
Private Sub Command10_Click()

Dim r As Long
Dim sSelected As String
Dim rc As RECT

Dim avgWidth As Single
Dim newWidth As Long

Dim i As Long
Dim NumOfChars As Long
Dim LongestSoFar As Integer
Dim LongestIndex As Long

'loop through the combo entries, using SendMessage
'with CB_GETLBTEXTLEN to determine the longest item
'in the dropdown portion of the combo
For i = 0 To Combo1.ListCount - 1

NumOfChars = SendMessage(Combo1.hwnd, CB_GETLBTEXTLEN, i, 0)
If NumOfChars > LongestSoFar Then
LongestSoFar = NumOfChars
LongestIndex = i
End If


'get the length of the longest combo item
'and calc its average width. Add .5 to round up
sSelected = (Combo1.List(LongestIndex))

r = DrawText(Form1.hDC, sSelected, -1&, rc, DT_CALCRECT)
avgWidth = rc.Right / Len(sSelected)

'calc the combo's new width by multiplying the
'average * number of characters, and adding the
'system metrics for a scrollbar
newWidth = (Len(sSelected) * avgWidth) + (cScrollWidth * 2)

'resize the dropdown portion of the combo box
r = SendMessage(Combo1.hwnd, CB_SETDROPPEDWIDTH, newWidth, 0)

'reflect the new dropdown list width in Label4
r = SendMessage(Combo1.hwnd, CB_GETDROPPEDWIDTH, 0, 0)

End Sub

No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.

Replying to a Comment...

Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2018 All Rights Reserved. Conditions