怎样使TextBox控件的滚动条永远在最后?? VB
2个回答
展开全部
使用API函数可以实现滚动到文本框的任意一行。方法是向文本框发送EM_LINESCROLL 来滚动文本。wParam参数表明横向移动的字符数,而lParam是纵向移动的行数。下面是一个例子:
首先建立一个窗体,在其上放置两个按钮、一个文本框。将文本框的MultiLine属性设为True,ScrollBars属性设为3-Both。
然后输入以下代码:
Const EM_LINESCROLL = &HB6
Private Declare Function SendMessage Lib "User32" Alias _
"SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Private Sub Form_Load()
Dim intLineIndex As Integer, intWordIndex As Integer
'Initialize Text1.
Text1.Font = "Courier New"
Text1.Text = ""
For intLineIndex = 1 To 25 'Add 25 lines of text.
Text1.Text = Text1.Text & "Line" & Str$(intLineIndex)
For intWordIndex = 1 To 5 'Make each line 12 words
'long.
Text1.Text = Text1.Text & " Word" & Str$(intWordIndex)
Next intWordIndex
Text1.Text = Text1.Text & vbCrLf
Next intLineIndex
Command1.Caption = "Vertical"
Command2.Caption = "Horizontal"
End Sub
Private Sub Command1_Click()
Dim lngRet As Long
lngRet = SendMessage(Text1.hWnd, EM_LINESCROLL, 0, 5&)
End Sub
Private Sub Command2_Click()
Dim lngRet As Long
lngRet = SendMessage(Text1.hWnd, EM_LINESCROLL, 5, 0&)
End Sub
首先建立一个窗体,在其上放置两个按钮、一个文本框。将文本框的MultiLine属性设为True,ScrollBars属性设为3-Both。
然后输入以下代码:
Const EM_LINESCROLL = &HB6
Private Declare Function SendMessage Lib "User32" Alias _
"SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Private Sub Form_Load()
Dim intLineIndex As Integer, intWordIndex As Integer
'Initialize Text1.
Text1.Font = "Courier New"
Text1.Text = ""
For intLineIndex = 1 To 25 'Add 25 lines of text.
Text1.Text = Text1.Text & "Line" & Str$(intLineIndex)
For intWordIndex = 1 To 5 'Make each line 12 words
'long.
Text1.Text = Text1.Text & " Word" & Str$(intWordIndex)
Next intWordIndex
Text1.Text = Text1.Text & vbCrLf
Next intLineIndex
Command1.Caption = "Vertical"
Command2.Caption = "Horizontal"
End Sub
Private Sub Command1_Click()
Dim lngRet As Long
lngRet = SendMessage(Text1.hWnd, EM_LINESCROLL, 0, 5&)
End Sub
Private Sub Command2_Click()
Dim lngRet As Long
lngRet = SendMessage(Text1.hWnd, EM_LINESCROLL, 5, 0&)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询