Click to See Complete Forum and Search --> : No scrollbar in a listbox


Maarten Versteeg
January 10th, 2000, 09:27 AM
Hi,

Is it possible to have a listbox without a vertical scrollbar, when the list becomes longer then the lenght of the listbox?

Thanx, Maarten

Chris Eastwood
January 10th, 2000, 10:31 AM
I'm a bit confused as to why you'd want this, but here's how to do it any way :

Paste the following code into a new form (FORM1) containing a ListBox (LIST1) :


option Explicit
'
' Win API Declares
'
private Declare Function ShowScrollBar Lib "user32" (byval hwnd as Long, _
byval wBar as Long, byval bShow as Long) as Long
private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (byval hwnd as Long, byval nIndex as Long) as Long
private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (byval hwnd as Long, byval nIndex as Long, byval _
dwNewLong as Long) as Long
'
'
private Const SB_VERT = 1
private Const WS_VSCROLL = &H200000
private Const GWL_STYLE = (-16)
'
'
private Sub Form_Load()
'
Dim l as Long
Dim lStyle as Long
'
' Add some items to the scrollbar
'
for l = 1 to 255
List1.AddItem "Item " & l
next
'
' Hide any visible scrollbar
'
ShowScrollBar List1.hwnd, SB_VERT, 0
'
' get Window Style Bit
'
lStyle = GetWindowLong(List1.hwnd, GWL_STYLE)
'
' Remove Scrollbar from style
'
lStyle = lStyle Xor WS_VSCROLL
'
' set the new window style of the listbox
'
lStyle = SetWindowLong(List1.hwnd, GWL_STYLE, lStyle)
'
End Sub







Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Maarten Versteeg
January 11th, 2000, 05:54 AM
It works just like I want to.
Great work.

Thanx very much!!!