获取richtextbox插入位置索引号
问题描述:
Hello All,
我使用的是richtextbox,我需要将插入位置作为数字才能使用它,任何想法都可以获得索引号?
感谢您的帮助
我的尝试:
i不要找到任何方法,我在richtextbox函数中找不到任何返回我的索引编号的函数
Hello All,
I am using a richtextbox and i need to get the caret position as number in order to use it , any idea to get the index number ??
thanks for your help
What I have tried:
i don;t find anythimg and i don't find any function in richtextbox function that return to my the index number
答
谷歌是你的朋友:好好拜访他经常。他可以比在这里发布问题更快地回答问题......
快速搜索 使用您的主题作为搜索词 提供30,000次点击:获取richtextbox插入位置索引编号WPF - Google搜索 [ ^ ]
几乎立即领先于MSDN: RichTextBox,得到插入符号索引。 [ ^ ]
将来,请尝试自己做至少基础研究,不要浪费你的时间或我们的时间。
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search using your subject as the search term gave 30,000 hits: Get richtextbox caret position index number WPF - Google Search[^]
Leading almost immediately to MSDN: RichTextBox, getting caret index.[^]
In future, please try to do at least basic research yourself, and not waste your time or ours.
你可以使用RichTextBox.CaretPosition
[ ^ ]属性,用于访问内容中插入符号的当前索引。
以下代码是从MSDN捕获的,
You can useRichTextBox.CaretPosition
[^] property to access the current index of caret inside the content.
Following code was captured from MSDN,
// Create a new FlowDocument, and add 3 paragraphs.
FlowDocument flowDoc = new FlowDocument();
flowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 1")));
flowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 2")));
flowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 3")));
// Set the FlowDocument to be the content for a new RichTextBox.
RichTextBox rtb = new RichTextBox(flowDoc);
// Get the current caret position.
TextPointer caretPos = rtb.CaretPosition;
// Set the TextPointer to the end of the current document.
caretPos = caretPos.DocumentEnd;
// Specify the new caret position at the end of the current document.
rtb.CaretPosition = caretPos;
您可以看到这些是如何操作文档中的插入位置的一些方法,你可以得到位置,以及设置位置。
You can see that these are a few of the methods how you can manipulate the caret position inside the document, you can get the position, as well as set the position.