• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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