VB6.0 的richtextbox控件中如何使滚动条始终向下
发布网友
发布时间:2023-09-05 03:54
我来回答
共2个回答
热心网友
时间:2024-11-13 00:14
一. 显示时滚动条始终在下:// 让光标定位到文本框末尾
richTextBox1.Select(richTextBox1.TextLength, 0);//然后移动滚动条,使输入点(text entry point)(即光标所在的位置)显示出来
//这样也可以达到滚动到最下方的目的
richTextBox1.ScrollToCaret(); 二. 输入时滚动条始终在下:richTextBox1的TextChanged事件
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
this.richTextBox1.SelectionStart = int.MaxValue;
this.richTextBox1.ScrollToCaret();
}
int.MaxValue要比较大。用int.MaxValue安全
热心网友
时间:2024-11-13 00:15
可以向文本框发送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