如何将文本连续输出到 RichTextBox 并使其在视觉上引人注目?

How continually output text to a RichTextBox with it being visually noticeable?

我现在正尝试创建自己的 VB 项目以熟悉该语言,我希望它做的就是不断地在 RichTextBox 的下一行打印一个字符串。
我无法弄清楚的问题是让它一个接一个地打印,它是一次打印。我在下面有一些代码来显示我现在所在的位置。

我试过使用不同的计数方法,根据它的设置方式,调试器甚至不会加载...

Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
Friend WithEvents Button1 As System.Windows.Forms.Button

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
End Sub
Private Sub RTB1_TextChanged(sender As System.Object, e As System.EventArgs)
End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim counter1 As Integer = 0
    Dim i As String = "- I" & vbCrLf

    While counter1 <= 10
        Timer1.Interval = 1000
        Timer1.Start()
        i = i + i
        counter1 += 1
    End While

    RichTextBox1.Text = i


    'Loop

    'Environment.NewLine

End Sub
Friend WithEvents TableLayoutPanel2 As System.Windows.Forms.TableLayoutPanel

Private Sub TableLayoutPanel2_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles TableLayoutPanel2.Paint

End Sub
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox

Private Sub RichTextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.TextChanged
    RichTextBox1.SelectionStart = RichTextBox1.Text.Length
    RichTextBox1.ScrollToCaret()
End Sub
Friend WithEvents Timer1 As System.Windows.Forms.Timer

感谢所有花时间查看此内容并帮助我的人!
我真的在寻找我的输出以向下滚动 RichTextBox 并不断地一次又一次地在新行上输出一个字符串。

如描述:

  • 创建 System.Windows.Forms.Timer。有不同类型的定时器可用。这是您需要更新 UI 组件的组件,因为它的 Tick 事件是在 UI 线程中引发的。
  • 初始化定时器并将其间隔设置为 1 秒 (1000 ms)。初始化在表单的 Shown() 事件中执行,该事件在表单准备好呈现时引发(请参阅文档)。
  • 添加Timer.Tick事件处理程序(这里是在代码中添加的)
  • 初始化一个整数字段(这里称为timerCounter),每次计时器滴答时都会递增。
  • Tick 事件中,使用它的 AppendText() 方法向 RichTextBox 控件添加一行文本,该方法允许在不清除文本的情况下向控件添加文本。该方法对所有继承TextBoxBase的控件通用。

注:
我正在使用内插字符串 $"{Some value}" 将文本添加到 RichTextBox。如果您的 VB.Net 版本不支持它,请使用旧格式:

RichTextBox1.AppendText("Line number " & timerCounter.ToString() & Environment.NewLine)


Private rtbTimer As System.Windows.Forms.Timer
Private timerCounter As Integer = 0

Protected Sub TimerTick(sender As Object, e As EventArgs)
    timerCounter += 1
    RichTextBox1.AppendText($"Line number {timerCounter} {Environment.NewLine}")
    RichTextBox1.ScrollToCaret()
End Sub

Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
    rtbTimer = New Windows.Forms.Timer With { .Interval = 1000 }
    AddHandler rtbTimer.Tick, AddressOf TimerTick
    rtbTimer.Start()
End Sub