Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Horizontal Scrolling a List Box

Status
Not open for further replies.

briancoats

Programmer
May 1, 2003
61
US
I have inserted this code, which I found in this forum and changed to accept a passed form. It is in a module so it can be called from anywhere. None of that really matters. When I had the fontsize = 7 on my list box, it worked beautifully. I set the size back to 8, nad the hscroll doesnt go all the way to the end of the code. Any ideas why this would be. Strongm posted the original code that I ripped off. (At least I give credit when it is due.)

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Const LB_SETHORIZONTALEXTENT = &H194

Public Sub AddAndModifyHScroll(lst As ListBox, frm As Form)
' depends on the scalewidth
' if scalemode is Twips then Divide MaxWidth by TwipsPerPixel to get pixels
Dim lp As Long
Dim MaxWidth As Long

For a = 0 To lst.ListCount - 1
If frm.TextWidth(lst.List(a)) > MaxWidth Then MaxWidth = frm.TextWidth(lst.List(a))
Next

SendMessage lst.hwnd, LB_SETHORIZONTALEXTENT, MaxWidth / Screen.TwipsPerPixelX, 0
End Sub

Brian

"Give a man a fish and you feed him for a day. Teach him to fish and you feed him for a lifetime."
 
actually after further testing, It just gets the same width either way. Maybe i ma doing something wrong...

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top