CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2000
    Location
    Holland
    Posts
    14

    No scrollbar in a listbox

    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


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: No scrollbar in a listbox

    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

  3. #3
    Join Date
    Jan 2000
    Location
    Holland
    Posts
    14

    Re: No scrollbar in a listbox

    It works just like I want to.
    Great work.

    Thanx very much!!!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured