文本框行计数器(更复杂)VB.NET

文本框行计数器(更复杂)VB.NET

问题描述:

IM深成(为乐趣和学习)的编程和我有问题,我 知道如何计算在文本线,这个简单的代码文本框行计数器(更复杂)VB.NET

Label1.Text = Textbox1.Lines.Count 

但这代码不计算行时,我粘贴一些多行文本它计为一行。 是的,还有一个问题是有办法让行计数器现场, 我试图

Private Sub Textbox1_TextChanged(sender As Object, e As EventArgs) Handles Page_Names.TextChanged 
Label1.Text = Textbox1.Lines.Count 
End Sub 

但这再现了许多滞后。 “多行”的文本

的例子,我要粘贴

[email protected] 
[email protected] 
email[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 

对不起,愚蠢的问题即时通讯新,和抱歉不好英语:)

提前感谢!

+0

一个'TextBox'的'Lines'属性是通过自动换行的影响。如果你有很长的文本包装,但不包含换行符,那么'Lines.Count'将为1. – jmcilhinney

+0

WordWrap = false在我的文本框中,我尝试了例如在那里复制代理列表并且仍然只获得1作为结果 –

+0

我们能否知道什么是多线文本? – Subaz

由于名誉较低,我无法在添加评论部分回答它,因此在此张贴。 您的问题的解决方案是玩文本框属性。将AcceptReturn属性更改为文本框属性的true。

Multiline = true AcceptReturn = true 然后你可以做任何事情来计算文本框的行数。 就像添加一个按钮,一个标签,然后添加代码,如按钮单击事件。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Label1.Text = TextBox1.Lines.Count 
End Sub 

你处理一个不同的TextBox的TextChanged事件,你要计算的行数。

试试这个:

Private Sub Textbox1_TextChanged(sender As Object, e As EventArgs) Handles Textbox1.TextChanged 
Label1.Text = Textbox1.Lines.Count 
End Sub