Scrolling a text box
Have you ever wanted to be able to scroll a textbox automatically to the bottom each time you add some text? Here's how:
Author: Oystein Selbekk'API declares: Declare Function PutFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long 'Function to scroll virtually any box that has this capability: Function ScrollText(MyControl As Control, vLines As Integer) as long Dim Success As Long Dim SavedWnd As Long Dim R As Long Dim Lines As Double Const EM_LINESCROLL = &HB6 ' Get the window handle of the control that currently has the focus SavedWnd = Screen.ActiveControl.hwnd Lines = vLines ' Set the focus to the passed control. MyControl.SetFocus ' Scroll the lines. Success = SendMessage(MyControl.hwnd, EM_LINESCROLL, 0, Lines) ' Restore the focus to the original control. R = PutFocus(SavedWnd) ' Return the number of lines actually scrolled. ScrollText = Success End Function 'Example on how you use it: Call ScrollText(Text1, 20) 'This example scrolls the text1 textbox 20 lines downward. If you want to scroll down to the bottom, make sure you specify more lines than max possible content! |
||
Editor: Oystein Selbekk Last update: 2024-11-21 Copyright 1995-2024 VBI |