In Visual Basic, you can scroll through the content in the text box control, without waiting for the user to click the scroll control, you can send one or more scroll messages to the system by using the Windows API's SendMessage function. .
Stroke in text box control ---- In the sample case in the lower surface, connect to the code on the LEFT command button to move the contents of the content in this box to the left. This message is sent to the window when the user hits the water flat scroll bar on this box control. However, in this program, it is sent to send this message when the user clicks the command button.
---- To control the direction of the scroll line, you must tell the SendMessage function to send a WM_HSCROLL message to the text box control, and specify the direction parameter in the WPARAM parameter. The lower surface is a valid settings specified in the WPARAM parameter.
---- SB_LEFT to move more parts to the left ---- SB_RIGHT to move more parts to the right ---- SB_LINELEFT Move a single unit ---- SB_Lineright moves a single unit to the right
---- It is visible, to move the text in the text box to the left, you can set the wPAram parameter to SB_LINELEFT; to move the content in the text box to the right, set the wparam parameter to SB_Lineright, etc. .
Sample case ---- This program shows how to use the SendMessage function to scroll the content in this box control.
---- 1. In the Visual Basic, a new process is started, using the default method to build FORM1. ---- 2. Add the following constants and declaration statements to the General Declaration section of the Form1 (note that the declaration statement needs to be written in one line): ---- Private Declare Function SendMessage Lib "User32" Alias "SendMessagea" (Byvala " HWnd As Long, Byval WMSG As Long, Byval WParam As INTEGER, BYVAL LPARAM As Long AS Long ---- Const SB_Lineright = 1 ---- Const SB_LINELEFT = 0 ---- Const WM_HSCROLL = & H114
---- 3. Add a text box control on Form1, and use the default method to build TEXT1. Setting its multiline property to true, Scroolbars property is set to 3-Both.
---- 4. Add a command button control on Form1 to use the default method to build Command1. ---- Set its CAPTION attribute to "left".
---- 5. Add to Command1 to Command1 as the following code: private submmand1_click () DIM X as long x = sendMessage (Text1.hwnd, WM_HSCROLL, SB_LINELEFT, BYVAL 0 &) End Sub
---- 6. Add the second command button control on Form1, and use the default method to build Command2. ---- Set its CAPTION property to "right".
---- 7. Add to the COMMAND2 in the COMMAND2:
PRIVATE SUB Command2_Click () DIM X as long x = sendMessage (Text1.hwnd, WM_HSCROLL, SB_LINERIGHT, BYVAL 0 &) End Sub
---- Press the F5 key to execute the program. Type some text in text box control, as shown in Figure 1. Click the left command button, text will be scroll a character to the left, as shown in Figure 2. Click the right command button, and the text will scroll the position of a character to the right, as shown in Figure 3.