RichTextBox垂直自动滚动文本

时间:2016-06-19 08:23:41

标签: vb.net richtextbox

我需要建立一个数字标牌应用程序,它将显示公告。因为文本有能力通过设计成为用户,我想到了一个富文本框控件,文本将自动垂直滚动(如“新闻”文本框)。 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

好的,我正在等你的火车时正在为你写这篇文章所以我没有测试过这个,但是这样的事情应该可以解决问题。

注意
如果您收到CheckForIllegalCrossThreadCalls 错误 ,则除了调试目的外,不要将其设置为CheckForIllegalCrossThreadCalls = False
虽然你一开始没有注意到任何事情,CheckForIllegalCrossThreadCalls = False可能会在以后的轨道上引起问题。

总而言之,这是代码。

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TextBox1.SelectionStart = 0 ''Change to a RichTextBox if you want.
    ''Starting the background worker.
    BackgroundWorker1.RunWorkerAsync()
End Sub

Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    ''BACKGROUND WORKER''
    For i = 0 To TextBox1.Text.Length
        TextBox1.SelectionStart = i
        System.Threading.Thread.Sleep(200)''changing the sleep time will make the textbox scroll to the right faster or slower.
    Next

End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    ''Once completed, The background worker will start again.
    TextBox1.SelectionStart = 0
    BackgroundWorker1.RunWorkerAsync()
End Sub

Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
    ''This should stop the program from crashing when closing if the background worker is still running
    BackgroundWorker1.CancelAsync()
End Sub
End Class

注意
您需要使用后台工作人员,否则在Loop完成之前,您的程序将无法响应。
再次如果您收到CheckForIllegalCrossThreadCalls错误,请查看Google并搜索以解决此问题,但是如果您愿意将其保留为CheckForIllegalCrossThreadCalls = False而不是由您决定。

让我知道你怎么走,我没有测试过这个,但是因为没有人在10个小时内回复你,我想我试试看,即使没有编译器来测试它。