hoTools.Find.FindAndReplace.SetRtfBoxText C# (CSharp) Method

SetRtfBoxText() public method

Output 'from' string to rtfBox and mark all possible changes. It returns the count of possible changes
public SetRtfBoxText ( System.Windows.Forms.RichTextBox rtfBox, string from ) : int
rtfBox System.Windows.Forms.RichTextBox
from string
return int
        public int SetRtfBoxText(RichTextBox rtfBox, string from)
        {
            int foundChanges = 0;
            rtfBox.ResetText();
            rtfBox.SelectionBackColor = Color.AliceBlue;
            //rtfBox.Text = ""; 

            int posInText = 0;
            Match match = _regExPattern.Match(from);
            while (match.Success)
            {
                foundChanges += foundChanges;
                // output not outputted text
                if ((match.Index - posInText) > 0)
                {
                    rtfBox.SelectionBackColor = Color.AliceBlue;
                    rtfBox.AppendText(from.Substring(posInText, match.Index - posInText));
                }
                rtfBox.SelectionBackColor = Color.Gold;
                rtfBox.AppendText(match.Value);
                posInText = match.Index + match.Length;
                match = match.NextMatch();

            }
            if ((from.Length - 1 - posInText) >= 0)
            {
                rtfBox.SelectionBackColor = Color.AliceBlue;
                rtfBox.SelectionBackColor = Color.AliceBlue;
                rtfBox.AppendText(from.Substring(posInText, from.Length - posInText));
            }
            return foundChanges;

        }
        #endregion

Usage Example

        /// <summary>
        /// Show the current item
        /// </summary>
        private void ShowItem()
        {
            // fill information
            _frItem = _fr.l_items[_fr.Index];
            _frItem.load(_fr.rep);

            txtType.Text    = _frItem.getType();
            txtSubType.Text = _frItem.getSubType();
            txtFrom.Text    = _fr.findString;
            txtTo.Text      = _fr.replaceString;

            // rtf fields
            _fr.SetRtfBoxText(rtfName, _frItem.Name);
            _fr.SetRtfBoxText(rtfStereotype, _frItem.Stereotype);
            _fr.SetRtfBoxText(rtfNotes, _frItem.Description);

            if (_fr.isTagSearch)
            {
                txtTaggedValueNames.Text     = string.Join(",", _fr.tagValueNames);
                txtTaggedValueNames.Visible  = true;
                lblTaggedValues.Visible      = true;
                gridTags.Visible             = true;
                gridTags.DataSource          = null;
                gridTags.AutoGenerateColumns = false;
                // load tags
                gridTags.DataSource = _frItem.l_itemTag;
            }
            else
            {
                txtTaggedValueNames.Text    = "";
                txtTaggedValueNames.Visible = false;
                lblTaggedValues.Visible     = false;
                gridTags.Visible            = false;
            }

            txtState.Text = StateCurrentItem() + " found";
        }