开发者

C# .NET RichTextBox GetCharOffsetFromPosition?

Is there a way to get character offset from a position?

I have a box that looks li开发者_StackOverflowke this -

C# .NET RichTextBox GetCharOffsetFromPosition?

I want to parse it character by character but I want to detect when it is superscript (which I achieved by setting SelectionCharOffset to 10

What I have is a loop that looks like this so I can acces the position with i

for (int i = 0; i < Text1.TextLength; i++) {
     //I can use things here like Text1.Text[i]...
}


The same way you achieved superscript.

Use the SelectionCharOffset property (along with SelectionStart and SelectionLength to select one character at a time) and see if its a positive number (since positive represents superscript and negative represents subscript).

for (int i = 0; i < Text1.TextLength; i++)
{
    Text1.SelectionStart = i;
    Text1.SelectionLength = 1;

    if (Text1.SelectionCharOffset > 0)
    {
        ...
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜