Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Horizontal Scroll for listbox

Anyone have the code for horizontal scroll in listbox?  I think there is an API to determine this.


Specialist
0
SPECIALIST
Asked:
SPECIALIST
1 Solution
 
twardCommented:
Public Const LB_SETHORIZONTALEXTENT = &H194

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


Public Sub AddHScrollToListBox(ByVal FormWithControl As Form, ByVal ListBox As Control, ByVal FullString As String)

  Dim ListHwnd As Long
  Static GreatestWidth As Long

  ' Get Focus of the ListBox to Make A Horizontal Scroll Bar For '
  ListBox.SetFocus
  ListHwnd = GetFocus()

  If FormWithControl.TextWidth(FullString) > GreatestWidth Then

    ' Add/Change Size of Horizontal Scroll Bar '
    Call SendMessage(ListHwnd, LB_SETHORIZONTALEXTENT, FormWithControl.TextWidth(FullString), NUL)
    GreatestWidth = FormWithControl.TextWidth(FullString)
    DoEvents

  End If

End Sub


0
 
SPECIALISTAuthor Commented:
Thanks I just have one error Getfocus says "sub or function not defined"

Just need that sub!

Specialist
0
 
CarlosJacCommented:
Declare Function GetFocus Lib "user32" Alias "GetFocus" () As Long

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
viktornetCommented:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
     (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long,
     ByRef lParam As Long) As Long

const LB_SETHORIZONTALEXTENT = 404

dim s as long

s = SendMessage(ListBox1.hWnd, LB_SETHORIZONTALEXTENT, 500, 0)

//Can you do like this in VB???->>> ListBox1.hWnd

Regards,
Viktor Ivanov
0
 
twardCommented:
Sorry about that, forgot the one declaration.  I would have posted it but someone beat me to it...
0
 
SPECIALISTAuthor Commented:
tward,

sorry I know you answered first, but I asked for clarification, after a few hours I had to re-post due to time limitations.

Sorry!
Specialist

0
 
SPECIALISTAuthor Commented:
One other thing, what is the 3rd argument?  fullstring as string?

should be ok after that!

Thanks
0
 
twardCommented:
The function I did gets called after anything is added to the Listbox so I pass the string that was added and try to calculate the size of the Scroll bar based on the Text that was added.
0
 
SPECIALISTAuthor Commented:
Thanks!
0
 
VingamelCommented:
Can somebody provide an example of calling this API function?  Thanks.
--Vingamel
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now