-
Mar 4th, 2011, 03:44 AM
#1
Thread Starter
New Member
[RESOLVED] vb6 - horizontal scrollbar not showing in listbox
Hi all,
I had include the API for the horizontal scroll bar but then it still not showing. below is the codes i included for the scrollbar. Can anyone please help me look at it and provide me some guidance?
Vb Code Code:
Public Sub getlistboxHScrollBar(str As String)
Dim x As Long
If x < TextWidth(str & " ") Then
x = TextWidth(str & " ")
If ScaleMode = vbTwips Then
x = x / Screen.TwipsPerPixelX ' if twips change to pixels
SendMessageByNum lstScript.hwnd, LB_SETHORIZONTALEXTENT, x, 0&
End If
End If
End Sub
I called this function whenever i add an item into the listbox
-
Mar 4th, 2011, 09:05 AM
#2
Re: vb6 - horizontal scrollbar not showing in listbox
Welcome to the forums.
Is your scalemode twips? If not, the SendMessage call is not even being triggered. Otherwise, what is the value of X, before & after the division, when you believe the scrollbar should have been displayed?
-
Mar 4th, 2011, 06:59 PM
#3
Re: vb6 - horizontal scrollbar not showing in listbox
If I remember correctly it has to do with the order in which you add the data and when you add the scrollbar but I don't remember which is correct. In other words it's either...
- Add the scrollbar
- Populate the listbox
or
- Populate the listbox
- Add the scrollbar
-
Mar 6th, 2011, 08:23 PM
#4
Thread Starter
New Member
Re: vb6 - horizontal scrollbar not showing in listbox
Thanks all. I had remove the scalemode but still it doesn't appear.
Does it work if my getscrollbar function is in formA, my listbox is in formA too but i call this function from formB?
I had also try to change the sequence but no luck.
-
Mar 6th, 2011, 10:20 PM
#5
Re: vb6 - horizontal scrollbar not showing in listbox
Originally Posted by lynnooi
Thanks all. I had remove the scalemode but still it doesn't appear.
Does it work if my getscrollbar function is in formA, my listbox is in formA too but i call this function from formB?
I had also try to change the sequence but no luck.
As long as it's a Public function then you do FormA.MyFunction
-
Mar 6th, 2011, 10:41 PM
#6
Thread Starter
New Member
Re: vb6 - horizontal scrollbar not showing in listbox
Ok. it's already a public function and there is no problem in calling it. no errors occur but the scrollbar did not show. Is there anything else which might cause it not showing?
-
Mar 7th, 2011, 06:06 PM
#7
Re: vb6 - horizontal scrollbar not showing in listbox
This works for me.
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Sub Form_Load()
Dim lLength As Long
List1.AddItem "1234567891011121314151617181920"
lLength = 2 * (List1.Width / Screen.TwipsPerPixelX)
Call SendMessage(List1.hWnd, LB_SETHORIZONTALEXTENT, lLength, 0&)
End Sub
-
Mar 7th, 2011, 07:41 PM
#8
Thread Starter
New Member
Re: vb6 - horizontal scrollbar not showing in listbox
Hi all,
Thanks a lot for the guidance. I got the horizontal scrollbar appeared. However, I not sure what is going on. It just appear after i delete the old list box and replace with a newly created listbox.
-
Mar 7th, 2011, 07:58 PM
#9
Re: [RESOLVED] vb6 - horizontal scrollbar not showing in listbox
If you are calling that routine for each item you add to your listbox, you can inadvertently reset it to where the scrollbar won't show. If the width of the text is less than client width of the listbox, the scrollbar will disappear. I think you'll want to keep track of the widest item and set the horizontal extent when a new widest item is added.
-
Sep 12th, 2024, 12:18 AM
#10
Member
Re: vb6 - horizontal scrollbar not showing in listbox
Originally Posted by lynnooi
Hi all,
Thanks a lot for the guidance. I got the horizontal scrollbar appeared. However, I not sure what is going on. It just appear after i delete the old list box and replace with a newly created listbox.
Realize the issue is marked as "resolved" but I'll give an update.
Working with VB6 under Windows 10
The following works perfectly, however, I had to delete and replace the listbox for the scrollbar to appear.
Declares:
Code:
'declare public function to add horizontal scroll bar to list box
Public 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
Public Const LB_SETHORIZONTALEXTENT = &H194
The subroutine to set the width:
Code:
Public Sub lstAddHScroll(argList As ListBox)
'the purpose of this subroutine is to add a horizontal scrollbar to a listbox
'call AFTER populating the listbox!
Dim i&
Dim lngBigWidth As Long
lngBigWidth = 0
For i& = 0 To argList.ListCount - 1
'find the longest item
'use "Me." preceding .TextWidth if working in a class module
If frmMetadata.TextWidth(argList.List(i&)) > lngBigWidth Then
lngBigWidth = frmMetadata.TextWidth(argList.List(i&))
End If
Next
'call function
'scale in twips - divide by 14
i& = SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, lngBigWidth \ 14, 0)
End Sub
-
Sep 12th, 2024, 04:08 AM
#11
Re: vb6 - horizontal scrollbar not showing in listbox
Originally Posted by SwampeastMike
Code:
'scale in twips - divide by 14
i& = SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, lngBigWidth \ 14, 0)
End Sub
You should use the "ScaleX" method, divide by 14 is not a thing.
Code:
SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, frmMetadata.ScaleX(lngBigWidth, frmMetadata.ScaleMode, vbPixels), 0)
-
Sep 12th, 2024, 06:58 AM
#12
Member
Re: vb6 - horizontal scrollbar not showing in listbox
Originally Posted by VanGoghGaming
You should use the "ScaleX" method, divide by 14 is not a thing.
Code:
SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, frmMetadata.ScaleX(lngBigWidth, frmMetadata.ScaleMode, vbPixels), 0)
Thank you! That didn't seem correct yet compared to the example I found (using a different divisor) at least it worked [with listboxes of the same width].
Really strange the way I had to delete and replace (using exact same name/settings) the listbox before the scroll bar appeared for longer entries.
-
Sep 12th, 2024, 10:27 AM
#13
Fanatic Member
Re: vb6 - horizontal scrollbar not showing in listbox
Originally Posted by VanGoghGaming
You should use the "ScaleX" method, divide by 14 is not a thing.
Code:
SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, frmMetadata.ScaleX(lngBigWidth, frmMetadata.ScaleMode, vbPixels), 0)
I formatted the PC and installed Windows 11.
Many times in projects that previously worked well, the error
error 16 expression too complex
Code:
If Form1.TextWidth(argList.List(i&)) > lngBigWidth Then
-
Sep 12th, 2024, 01:15 PM
#14
Re: [RESOLVED] vb6 - horizontal scrollbar not showing in listbox
As far as I know, the expression too complex error comes after using the "Not Not Array" syntax to check whether an array is initialized or not.
This syntax will destabilize the IDE and make it spit out the expression too complex nonsense.
If you need to check for an initialized array then it's recommended to dereference the array pointer:
Code:
GetMem4 ByVal ArrPtr(Array), pSA
If pSA = 0 Then ' Array is not yet initialized
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
|