与寻找下一个字的RichTextBox的问题 [英] Problem with finding the next word in RichTextBox

查看:149
本文介绍了与寻找下一个字的RichTextBox的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RichTextBox中输入一个字符,我想从它的TextRange的下一个字符。

As I enter a character in my RichTextBox, I want to get the next character from the its TextRange.

因此​​,这里是我如何做到这一点:

So here is how I do it:

TextPointer ptr1= RichTextBox.CaretPosition;
char nextChar = GetNextChar();
//we continue until there is a character
while (char.IsWhiteSpace(nextChar))
{
   ptr1= ptr1.GetNextInsertionPosition(LogicalDirection.Forward);
   nextChar = GetCharacterAt(Ptr1);
}
//so now ptr1 is pointing to a character, and we do something with that TextPointer
ChangeFormat(ptr1);

然后我得到了下一个字符的ptr1的,并从TextPointer,我得到的TextRange,做我的变化。

then I get the ptr1 of the next character and from the TextPointer, I get the TextRange, and do my changes.

因此,这里的问题?

在接下来的单词拼写正确,我没有问题,但如果它不是拼写正确,然后ptr1的不会指向下一个字(第二个字符)的第一个字符,如果我用GetNextContextPosition(LogicalDirection.Forward),它会给我的下一个单词的第一个字母,如果它的拼写错误。因此,根据其中只有一个工作的拼写?

when the next word is spelled correctly, I have no problem, but if it's not spelled properly then ptr1 would not point to the first character of the next word (the second character), and if I use GetNextContextPosition(LogicalDirection.Forward) it would give me the first letter of the next word if it's misspelled. So depending on the spelling only one of them works?

我只是想知道,如果你有关于这个问题的任何想法?有什么错,我在这里做什么?

I was just wondering if you have any idea about this problem? Is there anything wrong I am doing here?

推荐答案

我固定使用偏移量为这个问题是不相关的它是如何被拼写。这涉及到一个事实,即它抵消TextPointer会跳下后,我们添加任何文本。

I fixed the problem by using Offset as this is not related to how it's been spelled. This is related to the fact that it offset TextPointer would be jumped after we add any text.

因此​​,这里的修复:

So here is the fix:

INT指数= RichTextBox.CaretPosition.DocumentStart.GetOffsetToPosition(RichTextBox.CaretPosition);

int Index = RichTextBox.CaretPosition.DocumentStart.GetOffsetToPosition(RichTextBox.CaretPosition);

TextPointer ptr1= RichTextBox.CaretPosition.DocumentStart.GetPositionAtOffset(Index);

char nextChar = GetNextChar();
//we continue until there is a character
while (char.IsWhiteSpace(nextChar))
{
   Index++;
   ptr1= RichTextBox.CaretPosition.DocumentStart.GetPositionAtOffset(Index);
   nextChar = GetCharacterAt(Ptr1);
}
//so now ptr1 is pointing to a character, and we do something with that TextPointer
ChangeFormat(ptr1);

这篇关于与寻找下一个字的RichTextBox的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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