Vb.net vb文字计数器richtextbox覆盖多行
我正在编写新颖的管理软件,我需要能够准确地跟踪richtextbox中的字数。这就是我目前所拥有的Vb.net vb文字计数器richtextbox覆盖多行,vb.net,count,ms-word,richtextbox,writing,Vb.net,Count,Ms Word,Richtextbox,Writing,我正在编写新颖的管理软件,我需要能够准确地跟踪richtextbox中的字数。这就是我目前所拥有的 Dim Change As Integer Dim Count As Integer Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged Change = RichTextBox1.Text.Split(" ").ToLookup(F
Dim Change As Integer
Dim Count As Integer
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
Change = RichTextBox1.Text.Split(" ").ToLookup(Function(x) x).Count()
'Add 1 to the variable Change every time the space bar is pressed
Count = Change
If RichTextBox1.Text = "" Then
Count = 0
'If the textbox is empty, the word count is 0
ElseIf RichTextBox1.Text.EndsWith(" ") = True Then
Count = Change - 1
'take one away from the wordcount variable when the last character is a space
End If
ToolStripStatusLabel2.Text = Count
'Display the wordcount
End Sub
如何让代码在多行上继续运行?到目前为止,代码只在第一行的文本上运行。如果用户按enter键,然后继续键入,则单词计数不会对随后每行的第一个单词进行计数您可以在keydown处理程序中使用类似的内容。前导空格和尾随空格可能有一些特殊情况,除非它可以关闭1,并且应该处理后空格
If e.KeyValue = Keys.Space Or e.KeyValue = Keys.Back Then
ss = rText1.Text.Split
txCount.Text = UBound(ss) + 1
End If
你的问题是什么?@roryap opps。我编辑了这篇文章。keyvalue拒绝为我工作。不管怎样,我总是收到错误“keyvalue不是system.windows.forms.keyPressEventArgs的成员”。keypress事件使用keyPressEventArgs并具有参数e.KeyChar。keydown事件使用KeyEventArgs作为参数e.KeyValue。