c# - How to get First Char Index From Line in RichEditbox (UWP)? -


i trying find way determine index of first character in specific line in richeditbox (uwp)

in richtextbox easy

int indx1stlinchr = myrichtextbox.getfirstcharindexfromline(i); 

is there way or workaround method ?

a part coloring method in 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;          (int = 0; < 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;     } 

try snippet:

 private int getfirstcharindexofline(itextdocument document, int line)     {         string value;         document.gettext(textgetoptions.none, out value);          int size = 0;                      while (value.length > size)         {             itextrange range = document.getrange(size, size + 1);              size += range.expand(textrangeunit.line);              var lineindex = range.getindex(textrangeunit.line);              if (line == lineindex)             {                 //start of range first line character index                 return range.startposition;             }              size += 1;          }          return -1;     } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -