Community discussion forum

List box autoscroll

Tags: vb6 Canada
  • 4 years ago

    HI again... lol


    Im making a chat program that uses a listbox as its message window. But when the chat goes OVER the hieght of the list box the scroll bar appears but it doesnt scroll down automatically. How do i make it autoscroll to follow new items?


    Thanx

  • 4 years ago

    Put this in a standard module:

    Code:
    Private Const SBBOTTOM As Long = 7
    Private Const WM
    VSCROLL As Long = &H115


    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long


    Public Sub ScrollToBottom(ByVal hWnd as Long)
       SendMessage hWnd, WMVSCROLL, SBBOTTOM, ByVal 0&
    End Sub


    Now, say the list of messages is called lbMessages.  Whenever a new message arrives and you want to scroll to the bottom, just call the function:  
    ScrollToBottom lbMessages.hWnd
    .

  • 4 years ago
    Any Reason you are not using a Textbox with Locked = true, multiple = true, Scrollbar = vertical and text_change() with the line of code: text.SelStart = Len(text)?
  • 4 years ago

    i cant use a textbox because of the way the chat program is setup.


    Thx web for the code i have a good feeling itll work reallllllllly well


    also how would i limit the amount a chars a person could type becuz with the listbox setup if too many chars r entered it runs off the list
    Thx again lol



  • 4 years ago

    what do u mean?, what's wrong w/ the max length property?
    also, instead of scrolling down the list, u may want to work the list upwards, by setting the index to 0



    Shmosel

  • 4 years ago
    Thats not a bad idea but because all messengers scroll down it would get people confused and i dont want that to create negatove feedback on my program.

    BUT if i cant get it to autoscrol properly ill have to do that thanx for the suggestion
  • 4 years ago

    have you tried setting the ListIndex = listCount?

  • 4 years ago

    wow im surprised this hasnt fallen off the forums.... but what did u mean omni with listindex = listcount?

  • 2 years ago
    When ever the list box changes use this EASY bit of code.

    Listbox1.ListIndex = Listbox1.ListCount - 1

    It will scroll all the way to the bottom (or what ever list index you give it)... Big Smile [:D]

    Have fun,
    Jamin






Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback