Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows
Visual Basic > Forms sample source codes
Controlling the scrolling of a textbox
Controlling the scrolling of a textbox The following code shows how to scroll a multiline text box both horizontally and vertically. Option Explicit Private 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 'Purpose : Scrolls a Multiline textbox horizontally 'Inputs : lhwndTextbox The handle to the textbox. ' [bScrollRight] If True scrolls to the right, else scrolls left. ' [lNumCharacters] The number of characters to scroll. 'Outputs : Returns non zero number on success. 'Notes : The .ScrollBars property must include a horizontal scroll bar. 'Revisions : Function TextBoxHorizontalScroll(lhwndTextbox As Long, Optional bScrollRight As Boolean = True, Optional lNumCharacters As Long = 1) As Long Const SB_LINERIGHT = 1, SB_LINELEFT = 0, WM_HSCROLL = &H114 Dim lThisCharacters As Long If bScrollRight Then For lThisCharacters = 1 To lNumCharacters TextBoxHorizontalScroll = SendMessage(lhwndTextbox, WM_HSCROLL, SB_LINERIGHT, ByVal 0&) Next Else For lThisCharacters = 1 To lNumCharacters TextBoxHorizontalScroll = SendMessage(lhwndTextbox, WM_HSCROLL, SB_LINELEFT, ByVal 0&) Next End If End Function 'Purpose : Scrolls a Multiline textbox vertically 'Inputs : lhwndTextbox The handle to the textbox. ' [bScrollUp] If True scrolls upwards, else scrolls downwards. ' [lNumCharacters] The number of characters to scroll. 'Outputs : Returns non zero number on success. 'Notes : The .ScrollBars property must include a vertical scroll bar. 'Revisions : Function TextBoxVerticalScroll(lhwndTextbox As Long, Optional bScrollUp As Boolean = True, Optional lNumCharacters As Long = 1) As Long Const SB_LINEUP = 0, SB_LINEDOWN = 1, WM_VSCROLL = &H115 Dim lThisCharacters As Long If bScrollUp Then For lThisCharacters = 1 To lNumCharacters TextBoxVerticalScroll = SendMessage(lhwndTextbox, WM_VSCROLL, SB_LINEUP, ByVal 0&) Next Else For lThisCharacters = 1 To lNumCharacters TextBoxVerticalScroll = SendMessage(lhwndTextbox, WM_VSCROLL, SB_LINEDOWN, ByVal 0&) Next End If End Function 'Demonstration code Private Sub Command1_Click() 'Move 5 characters left TextBoxHorizontalScroll Me.Text1.hwnd, False, 5 End Sub Private Sub Command2_Click() 'Move 5 characters right TextBoxHorizontalScroll Me.Text1.hwnd, True, 5 End Sub
Privacy Policy
|
Link to Us
|
Links