如何在RichTextBox中插入编号的项目符号列表

时间:2019-05-27 14:24:50

标签: vb.net

我正在尝试在用户选择按钮时插入编号的项目符号列表,这将使计数器递增

我已经在线搜索了问题以及不同类型的循环条件语句

Private Sub ToolStripButton16_Click(sender As Object, e As EventArgs) Handles ToolStripButton16.Click
    ToolStripButton16.CheckOnClick = False
    Dim i As Integer
    i = 0
    Dim numbList As String
    Dim buttonClickCount As Integer
    buttonClickCount = 0
    Do While (i = buttonClickCount)
        i += 1
        numbList = "            " & i & "." & vbCrLf
        RichTextBox1.AppendText(numbList)
    Loop
    buttonClickCount += 1
End Sub

预期结果:

1.
2.
3.
4.

1 个答案:

答案 0 :(得分:0)

可能不是最优雅的解决方案,但它应该将您带向正确的方向。

'Using a class variable here allows you to keep an "application state".
Dim buttonClickCount as Integer = 0

Private Sub ToolStripButton16_Click(sender As Object, e As EventArgs) Handles ToolStripButton16.Click

    ToolStripButton16.CheckOnClick = False

    buttonClickCount += 1
    Dim newValue As String = "            " & buttonClickCount  & "." & vbCrLf

    RichTextBox1.AppendText(newValue)
End Sub