多行的问题WPF的TextBox

编程入门 行业动态 更新时间:2024-10-25 20:23:30
本文介绍了多行的问题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

本文发布于:2023-11-12 05:05:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WPF   TextBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!