Beispiel #1
0
        private void updateAllText(string item, Color clr, ColorUseFor use)
        {
            // store the current selection for restoring
            int length        = richTextBoxInput.SelectedText.Length;
            int start_pos_old = richTextBoxInput.SelectionStart;

            if (use == ColorUseFor.background)
            {
                int start_pos = 0;
                while (start_pos < richTextBoxInput.Text.Length)
                {
                    int index = richTextBoxInput.Text.IndexOf(item, start_pos);
                    if (index == -1)
                    {
                        break;
                    }

                    // For English like text, word is usaully separated by space, comma, etc,
                    // so need match "whole" word
                    if (m_isEnglishLikeText)
                    {
                        if (index != 0 && !isSeparator(richTextBoxInput.Text[index - 1]))
                        {
                            // the char before is not a separator
                            start_pos = index + item.Length;
                            continue;
                        }
                        if ((index + item.Length != richTextBoxInput.Text.Length) &&
                            !isSeparator(richTextBoxInput.Text[index + item.Length]))
                        {
                            // the char after is not a separator
                            start_pos = index + item.Length;
                            continue;
                        }
                    }

                    richTextBoxInput.Select(index, item.Length);
                    richTextBoxInput.SelectionBackColor = clr;

                    Console.Write("\"" + item + "\" is found at " + index + " and is marked / unmarked also\n");

                    start_pos = index + item.Length;
                }
            }

            // restore the selection
            richTextBoxInput.Select(start_pos_old, length);
        }
Beispiel #2
0
        private void removeFromListAndUpdateAllText(List <string> list, Color clr, ColorUseFor usdFor)
        {
            string selectedText = richTextBoxInput.SelectedText;

            if (list.Count > 0)
            {
                List <string> listCopy = new List <string>(list.ToArray());
                foreach (string item in listCopy)
                {
                    if (selectedText.Contains(item))
                    {
                        if (removeFromList(item, list))
                        {
                            updateAllText(item, clr, usdFor);
                        }
                    }
                }
            }
        }
Beispiel #3
0
 private void addToListAndUpdateAllText(string text, List <string> list, Color clr, ColorUseFor usdFor)
 {
     if (addToList(text, list))
     {
         updateAllText(text, clr, usdFor);
     }
 }