|
-
Feb 5th, 2004, 04:53 AM
#1
Thread Starter
Junior Member
Listbox scrolling
I have a listbox where I'm adding items as my applications runs over time.
However, I'm not getting any horizontal scrollbars even though the size of my text entries is longer than my listbox width. I do get vertical scrollbars when my list grows bigger than the listbox's height, but nothing for horizontal scrolling.
What do I need to do?
Thanks.
-
Feb 5th, 2004, 05:24 AM
#2
Junior Member
The normal ListBox VB doesn't have a horizontal scroll bar. To add a horizontal scroll bar to the control, you can call the Windows API SendMessage function with the LB_SETHORIZONTALEXTENT constant.
Sample Code
Option Explicit
Private Declare Function SendMessageByNum 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
Private Sub Command1_Click()
Dim s As String
Static x As Long
s = InputBox("Please enter any text", "List scroll", _
"this is a simple scrollbar sample for demonstration purposes")
List1.AddItem s
If x < TextWidth(s & " ") Then
x = TextWidth(s & " ")
If ScaleMode = vbTwips Then _
x = x / Screen.TwipsPerPixelX ' if twips change to pixels
SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, x, 0
End If
End Sub
"A child of five could understand this. Fetch me a child of five." Groucho Marx
-
Sep 17th, 2004, 12:52 PM
#3
Addicted Member
Originally posted by JOW
The normal ListBox VB doesn't have a horizontal scroll bar. To add a horizontal scroll bar to the control, you can call the Windows API SendMessage function with the LB_SETHORIZONTALEXTENT constant.
Sample Code
Option Explicit
Private Declare Function SendMessageByNum 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
Private Sub Command1_Click()
Dim s As String
Static x As Long
s = InputBox("Please enter any text", "List scroll", _
"this is a simple scrollbar sample for demonstration purposes")
List1.AddItem s
If x < TextWidth(s & " ") Then
x = TextWidth(s & " ")
If ScaleMode = vbTwips Then _
x = x / Screen.TwipsPerPixelX ' if twips change to pixels
SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, x, 0
End If
End Sub
Is there a Not-Normal ListBox I can use without all this code? I'm not sure where to place all this code.
-
Sep 17th, 2004, 01:21 PM
#4
Lets make it easier to add:
VB Code:
'goes in to a form
Option Explicit
Private Declare Function SendMessageByNum 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
Private Sub Form_Load()
List1.AddItem "This is very long text here and it doesn't fit into the listbox because it is so darn long!"
SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, 800, 0
End Sub
Make a sample project with that code and add a listbox. Then see how it works. 800 = 800 pixels.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|