WPF: richtextbox选项卡问题
本文关键字:问题 选项 richtextbox WPF | 更新日期: 2023-09-27 18:04:37
我真的很困惑这里发生了什么。我有一个rtb,我有allowTab设置为true,所以用户可以缩进。
问题是,文本前面似乎没有制表符。例如,如果我有这样的文本:
this is some text
and some more text
and one more line
我想象一下,如果我看一下代码中的文本,它看起来像:
this is some text 'r'n'tand some more text'r'n'tand one more line
但是它看起来就像:
this is some text 'r'nand some more text'r'nand one more line (notice there are
no tabs)
制表符对我来说非常重要,因为我需要跟踪行的"层次结构",我需要知道行之前有多少空间。(空格或制表符('t))。当我在代码中查看字符串时,是否有一种方法可以将制表符空间视为't ?
我应该抓住按下键事件,并用空格替换tab键事件吗?这就是我在winforms项目中做的,但我认为WPF会有一些简洁的方法来处理它:)
谢谢!
编辑当我点击制表键时,它会改变段落文本吗?也就是说,文本本身没有明显的区别吗?
我不知道你是如何得到文本回来,但它应该工作,测试:
string text = "this is some text 'r'n'tand some more text'r'n'tand one more line";
richTextBox1.AppendText(text);
text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;
//text will be the same: "this is some text 'r'n'tand some more text'r'n'tand one more line'r'n"