我创建多行文本框 链接工作更好但如果我想设置文本框文字计数器
I creating multiline TextBox with this Link its work better but if I want to set TextBox text counter
label1.Content = textBox1.Text 。长度;
以上行的工作很好,但问题是,当我按在文本框对付它会增加文本框计数器2个字符。
with above line work fine but problem is that when I press enter in the TextBox counter it will increase 2 characters in TextBox counter.
我怎样才能做这个任务,请帮助我的。
How can I do this task please help me.
任何帮助表示赞赏!
推荐答案安德烈Gordeev的答案是正确的(+1他),但不提供您的问题的直接解决方案。如果检查 textBox1.Text 字符串与调试器,你会看到简称 \r\\\ 字符。在另一方面,如果你打算直接影响他们的(通过 .Replace ,例如),你不会得到任何东西。
Andrey Gordeev's answer is right (+1 for him) but does not provide a direct solution for your problem. If you check the textBox1.Text string with the debugger you would see the referred \r\n characters. On the other hand, if you intend to affect them directly (via .Replace, for example), you wouldn't get anything.
因此,实际的回答你的问题是:依靠 Environment.NewLine 。示例代码:
Thus, the practical answer to your question is: rely on Environment.NewLine. Sample code:
label1.Content = textBox1.Text.Replace(Environment.NewLine, "").Length;更多推荐
多行的问题WPF的TextBox
发布评论