我正在尝试找到一种方法来确定 RichEditBox (UWP) 中特定行中第一个字符的索引
在 Richtextbox 中很容易
int indx1stlinchr = myRichTextBox.GetFirstCharIndexFromLine(i);
有没有办法做到这一点或解决方法?
我在 Winforms Richtextbox 中的着色方法的一部分
public void colorTheText(string rohtext)
{
myRichTextBox.SelectionLength = 0;
int def = network.SubSop_Deff;
var line = Regex.Split(rohtext, "\n|\r|\n\n");
int ipclassRange = CColor.KlassebitsRange(network.Network_Class, network.Netmask_length);
int k = 1;
int l = 1;
for (int i = 0; i < line.Length; i++)
{
int indx1stlinchr = myRichTextBox.GetFirstCharIndexFromLine(i);
int indexlinedge = line[i].LastIndexOf(" ");
if (line[i].StartsWith(">Network") == true)
{
myRichTextBox.SelectionLength = 0;
myRichTextBox.Select(indx1stlinchr, 12);
myRichTextBox.SelectionColor = Color.Black;
myRichTextBox.Select((indx1stlinchr + 13), 19);
myRichTextBox.SelectionColor = Color.Blue;
if (network.Reserved_IP != null)
{
myRichTextBox.SelectionLength = 0;
myRichTextBox.Select((indx1stlinchr + 76), 13);
myRichTextBox.SelectionColor = Color.Green;
}
if (ipclassRange > 0)
{
myRichTextBox.Select(indx1stlinchr + 39, ipclassRange);
myRichTextBox.SelectionColor = Color.Green;
}
myRichTextBox.SelectionLength = 0;
}
if (line[i].StartsWith("Netmask") == true)
{
myRichTextBox.SelectionLength = 0;
myRichTextBox.Select(indx1stlinchr, 19);
myRichTextBox.SelectionColor = Color.Black;
myRichTextBox.Select((indx1stlinchr + 13), 19);
myRichTextBox.SelectionColor = Color.Blue;
myRichTextBox.Select((indx1stlinchr + 38), 38);
myRichTextBox.SelectionColor = Color.Red;
myRichTextBox.SelectionLength = 0;
if (super == false)
{
indxlinstrt = myRichTextBox.GetFirstCharIndexOfCurrentLine();
if (k == 1)
{
myRichTextBox.Select(indxlinstrt + indexlinedge, (def + 4) * -1);
subrange = CColor.FindeSubRange(Regex.Split(myRichTextBox.SelectedText, ""), network.Netmask_length, def);
k = 0;
}
myRichTextBox.Select(indxlinstrt + indexlinedge, subrange);
myRichTextBox.SelectionColor = Color.DarkViolet;
myRichTextBox.SelectionLength = 0;
}
}//.........etc
}
super = false;
k = 1;
}