多行的问题WPF的TextBox [英] Multiline issue WPF TextBox

查看:648
本文介绍了多行的问题WPF的TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建多行文本框 链接工作更好但如果我想设置文本框文字计数器

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆