【问题标题】:Underlining repeated words in VB在VB中为重复的单词加下划线
【发布时间】:2017-01-31 18:45:33
【问题描述】:

作业,我需要创建一个类似http://typeracer.com/ 的程序。

这是我到目前为止所做的:

Dim strContent As String = "the texts the text the text"
Dim arrNum As Integer = 0

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    arrContent = strContent.Split(" ")
    RichTextBox2.Text = strContent
End Sub

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    If TextBox1.Text = arrContent(arrNum) + " " Then
        TextBox1.Clear()
        arrNum = arrNum + 1
    End If
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim strSearch As String = arrContent(arrNum)
    Dim intIndex As Integer = RichTextBox2.Find(strSearch, 0, RichTextBoxFinds.WholeWord)
    If intIndex <> -1 Then
        RichTextBox2.SelectionStart = intIndex 
        RichTextBox2.SelectionLength = strSearch.Length            
        RichTextBox2.SelectionFont = New Font(RichTextBox2.Font, FontStyle.Bold)
    End If
End Sub

问题是重复的单词没有下划线,为什么?

【问题讨论】:

    标签: arrays vb.net string richtextbox underline


    【解决方案1】:

    它没有下划线,因为您将它设置为粗体文本,而不是下划线。我想如果你在 Timer1_Tick 设置一个断点,你就不会命中它,因为你还没有启动计时器;如果尚未启用计时器,则需要启用它,然后启动它。

    将此添加到 Form1_Load

    Timer1.Enabled = True
    Timer1.Start()
    

    然后改变

    RichTextBox2.SelectionFont = New Font(RichTextBox2.Font, FontStyle.Bold)
    

    RichTextBox2.SelectionFont = New Font(RichTextBox2.Font, FontStyle.Underline)
    

    我试过这个并且下划线有效,但是您还有一些其他逻辑问题需要解决。如果内容中多次出现同一个词,则下划线逻辑将失败。当程序第一次启动时,它也不会在第一个单词下划线,一旦你在文本框中输入完所有单词,它也会出错,因为数组的索引将超出范围。但是现在下划线部分正在工作,您可以开始调试其余的东西

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 2017-01-05
      • 2017-12-04
      • 2021-04-22
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多