HOWTO: Scroll VB Text Box Programmatically and Specify LinesLast reviewed: September 30, 1997Article ID: Q147887 |
The information in this article applies to:
SUMMARYBy making a call to the Windows API function SendMessage, you can scroll text a specified number of lines or columns within a Microsoft Visual Basic for Windows text box. By using the SendMessage function, you can also scroll text programmatically, without user interaction. This technique extends Visual Basic for Windows' scrolling functionality beyond the built-in statements and methods. The sample program below shows how to scroll text vertically and horizontally a specified number of lines.
MORE INFORMATIONVisual Basic for Windows itself does not offer a statement for scrolling text a specified number of lines vertically within a text box. You can scroll text vertically by actively clicking the vertical scroll bar for the text box at run time; however, you do not have any control over how many lines are scrolled for each click of the scroll bar. Text always scrolls one line per click of the scroll bar. Furthermore, no built-in Visual Basic for Windows method can scroll text without user interaction. To work around these limitations, you can call the Windows API function SendMessage, as explained below.
Step-by-Step ExampleTo scroll the text a specified number of lines within a text box requires a call to the Windows API function SendMessage using the constant EM_LINESCROLL. You can invoke the SendMessage function from Visual Basic for Windows as follows: r& = SendMessage& (hWnd&, EM_LINESCROLL, wParam&, lParam&)
hWnd& The window handle of the text box. wParam& Parameter not used. lParam& The low-order 2 bytes specify the number of vertical lines to scroll. The high-order 2 bytes specify the number of horizontal columns to scroll. A positive value for lParam& causes text to scroll upward or to the left. A negative value causes text to scroll downward or to the right. r& Indicates the number of lines actually scrolled.The SendMessage API function requires the window handle (hWnd& above) of the text box. To get the window handle of the text box, use the hWnd property of the text box. For instance, if your text box's name is text1, text1.hWnd returns the window handle of that text box. Calling SendMessage to scroll text vertically does not require a vertical scroll bar, but the length of text within the text box should exceed the text box height. Below are the steps necessary to create a text box that scrolls five vertical lines each time you click the command button labeled "Vertical:"
Keywords : APrgWindow PrgCtrlsStd VB4ALL VB4WIN vbwin GnrlVb kbprg kbfasttip Technology : kbvba Version : WINDOWS:4.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |