自动滚动到底部的文本框 [英] Auto scroll to bottom with a textbox
问题描述
我有一个由ms access创建的mdb文件.它的内部有一个表单,表单内部有一个大文本框.
I have an mdb file made by ms access. It got a form inside and inside the form there are one large textbox.
制作此文本框的目的是通过在文本框内添加消息来显示某些工作的进度:
The intention of making this textbox is to show the progress of some work by adding messages inside the textbox:
txtStatus.value = txtStatus.value & "Doing something..." & vbCrLf
txtStatus.value = txtStatus.value & "Done." & vbCrLf
但是问题是,当文本的高度>文本框的高度时,不会自动显示新消息.文本框有一个滚动条,但是我必须手动滚动它.每当新文本弹出时,我都希望自动滚动到底部.
But the problem is, when the height of the text > height of the textbox, the new message is not displayed automatically. The textbox has a scroll bar, but I have to scroll it manually. I would like to auto scroll to the bottom whenever new text pop up.
我试图在On Change属性中添加此代码(从Internet复制),但是代码失败,它没有执行任何操作:
I tried to add this code(copied from internet) in the On Change property, but the code failed, it does nothing:
Private Sub txtStatus_Change()
txtStatus.SelStart = Len(txt) - 1
End Sub
我希望会有一些简单而美观的方法来实现这一目标.我不想添加一些只能在某些计算机上运行的代码,因为它依赖于Windows平台的内核/等.
I wish there would be some simple and beautiful way to achieve this. I don't want to add some code which only work on some computers due to its dependence on the windows platform's kernel/etc.
推荐答案
您可以通过调用子项来实现;
You can do it via a call to a sub;
AppendText "Bla de bla bla."
.
.
sub AppendText(strText As String)
with txtStatus
.setfocus '//required
.value = .value & strText & vbNewLine
.selstart = len(.Value)
end with
end sub
这篇关于自动滚动到底部的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!