Exemplo n.º 1
0
 private void ReplaceCaseMatch_CheckedChanged(object sender, EventArgs e)
 {
     if (this.ReplaceCaseMatch.Checked == false && this.ReplaceWholeMatch.Checked == false )
         f = RichTextBoxFinds.None;
     else
         f = RichTextBoxFinds.MatchCase;
 }
Exemplo n.º 2
0
        private void SelectString(string word, RichTextBoxFinds options)
        {
            if (string.IsNullOrEmpty(word))
            {
                return;
            }

            int index     = 0;
            int prevIndex = 0;

            while (index != -1)
            {
                prevIndex = index;
                index     = Find(word, index, options);
                if (index == -1 || prevIndex > index)
                {
                    index = -1;
                    continue;
                }

                if (index < this.TextLength)//str found
                {
                    SelectionBackColor = m_selectionBackground;
                    SelectionFont      = m_selectionFont;
                    SelectionColor     = m_selectionForeColor;

                    index += word.Length;
                }
            }
        }
Exemplo n.º 3
0
        void Find(RichTextBox richText, string text, bool matchCase, bool wraparound, bool updown)
        {
            RichTextBoxFinds options = RichTextBoxFinds.None;

            if (matchCase)
            {
                options |= RichTextBoxFinds.MatchCase;
            }
            if (updown)
            {
                options |= RichTextBoxFinds.Reverse;
            }

            int index;

            if (updown)
            {
                index = richText.Find(text, 0, richText.SelectionStart, options);
            }
            else
            {
                index = richText.Find(text, richText.SelectionStart + richText.SelectionLength, options);
            }

            if (index >= 0)
            {
                richText.SelectionStart  = index;
                richText.SelectionLength = text.Length;
            }
            else
            {
                MessageBox.Show("Cannot find \"" + text + "\"", "NotePad");
            }
        }
Exemplo n.º 4
0
        public void Find(RichTextBox richtext, string nhap, bool check_up)
        {
            //Khởi tạo giá trị RichTextBoxFinds = none.
            RichTextBoxFinds chose = RichTextBoxFinds.None;

            //nếu đã check vào radup. hay raduo.checked
            if (check_up)
            {
                //tìm kiếm chạy ngược từ dưới lên trên
                chose |= RichTextBoxFinds.Reverse;
            }
            // tạo biến int. như đã nói trên RichTextBox hỗ trợ phương thức int Find(...). giá trị trả về là int.
            int index;

            //neu check_up = true
            if (check_up)
            {
                index = richtext.Find(nhap, 0, richtext.SelectionStart, chose);
            }
            else
            {
                index = richtext.Find(nhap, richtext.SelectionStart + richtext.SelectionLength, chose);
            }
            if (index >= 0)
            {
                richtext.SelectionStart  = index;
                richtext.SelectionLength = nhap.Length;
            }
            else
            {
                MessageBox.Show(Application.ProductName + " has finished searching the document.",
                                Application.ProductName, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }
Exemplo n.º 5
0
 private void findTextDialog_FormClosed(object sender, FormClosedEventArgs e)
 {
     Debug.Assert(sender == findTextDialog);
     findTextLocation = findTextDialog.Location;
     findTextOptions  = findTextDialog.FindOptions;
     findTextDialog   = null;
 }
Exemplo n.º 6
0
        public int FindMyText(string text, int start, RichTextBoxFinds options)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(0);
            }

            if (_richTextBox.TextLength == 0)
            {
                return(0);
            }

            int returnValue = -1;

            if (text.Length > 0 && start >= 0)
            {
                if (start > _richTextBox.TextLength)
                {
                    return(-1);
                }

                int indexToText = _richTextBox.Find(text, start, options);

                if (indexToText >= 0)
                {
                    returnValue = indexToText;
                    _richTextBox.SelectionStart  = returnValue;
                    _richTextBox.SelectionLength = text.Length;
                }
            }

            return(returnValue + text.Length);
        }
        public void Highlight(string text, Color color)
        {
            if (String.IsNullOrWhiteSpace(text))
            {
                return;
            }

            int index;
            int start  = 0;
            int end    = _rtb.TextLength;
            int length = text.Length;
            RichTextBoxFinds options = RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase;
            int savedPos             = _rtb.SelectionStart;

            _rtb.SelectionBackColor = color;
            index = _rtb.Find(text, start, end, options);
            while (index >= 0)
            {
                _rtb.SelectionBackColor = color;
                start = index + length;
                index = _rtb.Find(text, start, end, options);
            }

            if (savedPos >= 0)
            {
                _rtb.Select(savedPos, 0);
            }
            else
            {
                _rtb.Select(0, 0);
            }
        }
Exemplo n.º 8
0
        public int FindMyText(string text, int start, bool match)
        {
            RichTextBoxFinds option = RichTextBoxFinds.None;

            if (match)
            {
                option |= RichTextBoxFinds.MatchCase;
            }
            else
            {
                option |= RichTextBoxFinds.None;
            }

            int returnValue = -1;

            returnValue = TextBox.Find(text, start, option);
            if (text.Length > 0 && start >= 0)
            {
                int indexToText = TextBox.Find(text, start, option);
                if (indexToText >= 0)
                {
                    returnValue = indexToText;
                }
            }

            return(returnValue);
        }
Exemplo n.º 9
0
        public void FindText(string text, RichTextBoxFinds options)
        {
            int start = 0;
            int end   = richTextBox.TextLength;

            if ((options & RichTextBoxFinds.Reverse) != 0)
            {
                end = richTextBox.SelectionStart + richTextBox.SelectionLength - 1;
            }
            else
            {
                start = richTextBox.SelectionStart + 1;
            }
            int found = richTextBox.Find(text, start, end, options);

            if (found == -1)
            {
                // Search the whole text file
                found = richTextBox.Find(text, options);
                if (found == -1)
                {
                    SystemSounds.Asterisk.Play();
                }
            }
        }
Exemplo n.º 10
0
        private void buttonReplaceAll_Click(object sender, EventArgs e)
        {
            bool             bFoundSomething = false;
            RichTextBoxFinds options         = MatchCase | WholeWords;

            for (int nIndex = m_rtb.Find(comboBoxFindWhat.Text, options);
                 nIndex != -1;
                 nIndex = m_rtb.Find(comboBoxFindWhat.Text, ++nIndex, options))
            {
                m_rtb.Select(nIndex, comboBoxFindWhat.Text.Length);

                if (String.Compare(m_rtb.SelectedText, comboBoxFindWhat.Text, IgnoreCase) == 0)
                {
                    m_rtb.SelectedText = comboBoxReplaceWith.Text;
                    bFoundSomething    = true;
                }
            }

            if (!bFoundSomething)
            {
                Console.Beep();
            }

            m_rtb.Focus();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Simple search box.
        /// </summary>
        /// <param name="richTextBox">The rich text box to search in.</param>
        /// <param name="finds">Specifies how a text search is carried out in a System.Windows.Forms.RichTextBox control.</param>
        public SearchBox(RichTextBox richTextBox, RichTextBoxFinds finds = RichTextBoxFinds.None)
        {
            InitializeComponent();

            _richTextBox = richTextBox;
            _finds       = finds;
        }
        private void Find()
        {
            RichTextBoxFinds richTextBoxFinds = RichTextBoxFinds.None;

            if (matchCaseCheckBox.Checked)
            {
                richTextBoxFinds |= RichTextBoxFinds.MatchCase;
            }
            if (matchWholeWordCheckBox.Checked)
            {
                richTextBoxFinds |= RichTextBoxFinds.WholeWord;
            }
            if (upRadioButton.Checked)
            {
                richTextBoxFinds |= RichTextBoxFinds.Reverse;
            }
            if (upRadioButton.Checked)
            {
                lastFoundIndex = richTextBox.Find(findTextBox.Text, 0, richTextBox.SelectionStart, richTextBoxFinds);
            }
            else
            {
                lastFoundIndex = richTextBox.Find(findTextBox.Text, richTextBox.SelectionStart + richTextBox.SelectionLength, richTextBoxFinds);
            }
            if (0 <= lastFoundIndex)
            {
                richTextBox.SelectionStart  = lastFoundIndex;
                richTextBox.SelectionLength = findTextBox.Text.Length;
            }
            replaceButton.Enabled = (0 <= lastFoundIndex);
        }
Exemplo n.º 13
0
 // bounded to Find event when the FindDialog is created.
 private void findDialog_Find(string findWhat, RichTextBoxFinds findOption)
 {
     int findIndex = 0;
     if (findWhat.Equals(m_foundWord))
         findIndex = m_foundIndex;
     if ( (findOption & RichTextBoxFinds.Reverse) == RichTextBoxFinds.Reverse)
     {
         findIndex = this.Find(findWhat, 0, findIndex, findOption);
     }
     else
     {
         findIndex = this.Find(findWhat, findIndex, findOption);
     }
     if (findIndex > 0)
     {
         m_foundWord = findWhat;
         if ( (findOption & RichTextBoxFinds.Reverse) == RichTextBoxFinds.Reverse)
         {
             m_foundIndex = findIndex;
         }
         else
         {
             m_foundIndex = findIndex + findWhat.Length;
         }
     }
 }
Exemplo n.º 14
0
        public bool Find(string text, SearchOptions options)
        {
            isFirstSearch = !text.Equals(findText);

            findText    = text;
            findOptions = options;

            RichTextBoxFinds finds = RichTextBoxFinds.None;

            if ((options & SearchOptions.BackwardSearch) > 0)
            {
                finds |= RichTextBoxFinds.Reverse;
            }
            if ((options & SearchOptions.CaseSensitive) > 0)
            {
                finds |= RichTextBoxFinds.MatchCase;
            }
            if ((options & SearchOptions.WholeWordsOnly) > 0)
            {
                finds |= RichTextBoxFinds.WholeWord;
            }

            int start = pad.SelectionStart;

            if ((options & SearchOptions.EntireScope) > 0)
            {
                start = 0;
            }

            int position = pad.Find(text, start, finds);

            return(position != start);
        }
Exemplo n.º 15
0
 private void WholeMatch_CheckedChanged(object sender, EventArgs e)
 {
     if (this.WholeMatch.Checked == false)
         option1 = RichTextBoxFinds.None;
     else
         option1 = RichTextBoxFinds.WholeWord;
 }
Exemplo n.º 16
0
 private void CaseMatch_CheckedChanged(object sender, EventArgs e)
 {
     if ( this.CaseMatch.Checked == false )
         option1 = RichTextBoxFinds.None;
     else
         option1 = RichTextBoxFinds.MatchCase;
 }
Exemplo n.º 17
0
        public void SelectStrings(ICollection <string> words, bool wholeWord)
        {
            if (words == null)
            {
                return;
            }

            if (m_isFailedStatus)
            {
                return;
            }

            RichTextBoxFinds options = (wholeWord ? RichTextBoxFinds.WholeWord : RichTextBoxFinds.None);

            foreach (string word in words)
            {
                if (word.Length > 1)
                {
                    SelectString(word, options);
                }
            }

            SelectionStart  = 0;
            SelectionLength = 0;
        }
Exemplo n.º 18
0
        private void btnFindNext_Click(object sender, EventArgs e)
        {
            RichTextBoxFinds options = RichTextBoxFinds.None;

            if (chkMatchCase.Checked)
            {
                options |= RichTextBoxFinds.MatchCase;
            }
            if (chkWholeWord.Checked)
            {
                options |= RichTextBoxFinds.WholeWord;
            }

            int index = rtbInstance.Find(txtSearchText.Text, lastFound, options);

            lastFound += txtSearchText.Text.Length;
            if (index >= 0)
            {
                rtbInstance.Parent.Focus();
            }
            else
            {
                MessageBox.Show("Search string not found", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information);
                lastFound = 0;
            }
        }
Exemplo n.º 19
0
        private void FindNextButton_Click(object sender, EventArgs e)
        {
            RichTextBoxFinds Options = RichTextBoxFinds.None;

            if (this.CaseSensitive.Checked == true)
            {
                Options |= RichTextBoxFinds.MatchCase;
            }
            if (this.DownRadioButton.Checked == true)
            {
                if (this.Parent.richTextBox1.SelectionLength > 0)
                {
                    this.Parent.richTextBox1.SelectionStart += this.Parent.richTextBox1.SelectionLength;
                    this.Parent.richTextBox1.SelectionLength = 0;
                }
                if (this.Parent.richTextBox1.Find(this.FindTextBox.Text, this.Parent.richTextBox1.SelectionStart, Options) < 0)
                {
                    MessageBox.Show(this, "找不到\"" + this.FindTextBox.Text + "\"", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            else if (this.UpRadioButton.Checked == true)
            {
                Options |= RichTextBoxFinds.Reverse;
                if (this.Parent.richTextBox1.SelectionLength > 0)
                {
                    this.Parent.richTextBox1.SelectionLength = 0;
                }
                if (this.Parent.richTextBox1.Find(this.FindTextBox.Text, 0, this.Parent.richTextBox1.SelectionStart, Options) < 0)
                {
                    MessageBox.Show(this, "找不到\"" + this.FindTextBox.Text + "\"", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }
Exemplo n.º 20
0
        private void findButton_Click(object sender, EventArgs e)
        {
            RichTextBoxFinds currOptions = upOrDown | matchCase | matchWord;
            int currPos = 0;

            if (startPosition >= 0 && !String.IsNullOrEmpty(searchBox.Text))
            {
                if ((currPos = dataBox.Find(searchBox.Text, startPosition, endPosition, currOptions)) != -1)
                {
                    if (upOrDown == RichTextBoxFinds.None)
                    {
                        startPosition = currPos + 1;
                    }
                    else
                    {
                        endPosition = currPos - 1;
                    }
                }
                else
                {
                    MessageBox.Show(
                        mainStrings.GetString("findBoxFinished"),
                        mainStrings.GetString("findBoxCaption"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
            }
        }
Exemplo n.º 21
0
        //private void btnUndoAll_Click(object sender, System.EventArgs e)
        //{
        //  if (undoRtf.Length > 0)
        //  {
        //    if (MessageBox.Show("Undo all replace operations?", "Verify Undo All", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
        //    {
        //      rtb.Rtf = undoRtf;
        //    }
        //    else
        //    {
        //      MessageBox.Show("Can't undo.", "Unable to Undo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        //    }
        //  }
        //}

        private void btnReplaceAll_Click(object sender, System.EventArgs e)
        {
            if (findText.Text.Length > 0)
            {
                // команда "Заменить все" выполняется через создание временного RichTextBox в котором изменяются
                // данные по частям, а результат передается в рабочий компонент, чтобы операция "Отменить"
                // была выполнена одним действием
                using (RichTextBox rtbTemp = new RichTextBox())
                {
                    rtbTemp.Rtf = rtb.Rtf;
                    int index = 0;
                    RichTextBoxFinds SearchOptions = (matchCase.Checked ? RichTextBoxFinds.MatchCase : 0)
                                                     | (wholeWord.Checked ? RichTextBoxFinds.WholeWord : 0);
                    int countReplace = 0;
                    while ((index = rtbTemp.Find(findText.Text, index, SearchOptions)) > -1)
                    {
                        rtbTemp.SelectedText = txbReplace.Text;
                        countReplace        += 1;
                        //rtbTemp.Select(curPos, txbReplace.TextLength);
                    }
                    if (countReplace > 0)
                    {
                        rtb.SelectAll();
                        rtb.SelectedRtf = rtbTemp.Rtf;
                    }
                    MessageBox.Show(string.Format("Готово. Число выполненых замен: {0}", countReplace));
                }
            }
        }
Exemplo n.º 22
0
        public FindDialog(RichTextBox richTextBox)
        {
            _logger      = richTextBox;
            _topLeft     = new Point(1, 1);
            _findOptions = RichTextBoxFinds.NoHighlight;
            _bottomRight = new Point(1, _logger.Height - 1);

            InitializeComponent();

            FindWhatTxt.DataBindings.Add("Text", this,
                                         nameof(FindWhat), false, DataSourceUpdateMode.OnPropertyChanged);

            NormalRd.DataBindings.Add("Checked", this,
                                      nameof(IsNormalMode), false, DataSourceUpdateMode.OnPropertyChanged);

            WrapAroundChckbx.DataBindings.Add("Checked", this,
                                              nameof(WrapAround), false, DataSourceUpdateMode.OnPropertyChanged);

            MatchCaseChckbx.DataBindings.Add("Checked", this,
                                             nameof(MatchCase), false, DataSourceUpdateMode.OnPropertyChanged);

            MatchWordChckbx.DataBindings.Add("Checked", this,
                                             nameof(MatchWord), false, DataSourceUpdateMode.OnPropertyChanged);

            UpRd.DataBindings.Add("Checked", this,
                                  nameof(IsDirectionUp), false, DataSourceUpdateMode.OnPropertyChanged);
        }
Exemplo n.º 23
0
 private void chkHighlightAll_CheckedChanged(object sender, System.EventArgs e)
 {
     if (findText.Text.Length > 0)
     {
         using (RichTextBox rtbTemp = new RichTextBox())
         {
             rtbTemp.Rtf = rtb.Rtf;
             int index     = 0;
             int countFind = 0;
             RichTextBoxFinds SearchOptions = (matchCase.Checked ? RichTextBoxFinds.MatchCase : 0)
                                              | (wholeWord.Checked ? RichTextBoxFinds.WholeWord : 0);
             while ((index = rtbTemp.Find(findText.Text, index, SearchOptions)) > -1)
             {
                 rtbTemp.SelectionBackColor = chkHighlightAll.Checked ? Color.Plum : Color.Transparent;
                 index      = rtbTemp.Text.IndexOf(findText.Text, index) + 1;
                 countFind += 1;
             }
             if (countFind > 0)
             {
                 if (rtb.CanUndo)
                 {
                     rtb.SelectAll();
                     rtb.SelectedRtf = rtbTemp.Rtf;
                 }
                 else
                 {
                     rtb.Rtf = rtbTemp.Rtf;
                 }
             }
         }
     }
 }
Exemplo n.º 24
0
        private void button_Next_Click(object sender, EventArgs e)
        {
            FormMain         formMain = (FormMain)this.Owner;
            RichTextBoxFinds option   = RichTextBoxFinds.None;

            if (checkBox_Case.Checked)
            {
                option |= RichTextBoxFinds.MatchCase;
            }

            if (checkBox_Word.Checked)
            {
                option |= RichTextBoxFinds.WholeWord;
            }

            Start = formMain.MyFind(textBox_Search.Text, Start, option);

            if (Start < 0)
            {
                MessageBox.Show("문자열을 찾을 수 없습니다!");

                Start = 0;
            }
            else
            {
                Start++;
            }
        }
Exemplo n.º 25
0
 private void mnuEditReplace_Click(object sender, EventArgs e)
 {
     if (txtTextArea.TextLength > 0)
     {
         int           location = txtTextArea.SelectionStart;
         string        text     = txtTextArea.SelectedText;
         ReplaceDialog dlg      = new ReplaceDialog(text);
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             currentSearchOpts   = (RichTextBoxFinds)0;
             currentSearchString = dlg.ReplaceString;
             if (dlg.CaseSensitive)
             {
                 currentSearchOpts |= RichTextBoxFinds.MatchCase;
             }
             currentSearchOpts |= (dlg.WholeWord) ? RichTextBoxFinds.WholeWord : RichTextBoxFinds.None;
             do
             {
                 location = txtTextArea.Find(currentSearchString, currentSearchOpts);
                 if (location > 0)
                 {
                     txtTextArea.SelectionStart  = location;
                     txtTextArea.SelectionLength = currentSearchString.Length;
                     txtTextArea.SelectedText    = dlg.ReplacementString;
                 }
             } while (location > 0 && dlg.ReplaceAll);
         }
     }
     else
     {
         OutputTextBox.Text = SharedStrings.NO_SEARCH_TEXT;
     }
 }
Exemplo n.º 26
0
//		private int Find()
//		{
////			found=true;
//			RichTextBoxFinds findOptions=RichTextBoxFinds.MatchCase;
////			if(matchCase.Checked)
////			{
////				findOptions|=RichTextBoxFinds.MatchCase;
////			}
//
//			int searchStart;
//			searchStart=textBox.SelectionStart+textBox.SelectionLength;
//			int findPosition=textBox.Find(findWhat.Text,searchStart,findOptions);
//			if(findPosition==-1)
//			{
//				searchStart=0; // continue search at the start of the document
//				passedEndOfDocument=true;
//				findPosition=textBox.Find(findWhat.Text,searchStart,findOptions);
////				if(findPosition==-1)
////				{
////					found=false;
////				}
//			}
//			return findPosition;
//		}
//		private void Replace()
//		{
////			bool ignoreCase=!matchCase.Checked;
////			int compared=String.Compare(textBox.SelectedText,findWhat.Text,ignoreCase);
//			if(textBox.SelectedText==findWhat.Text)
//			{
//				textBox.SelectedText=replaceWith.Text;
//			}
////			bool ignoreCase=!matchCase.Checked;
////			int compared=String.Compare(textBox.SelectedText,findWhat.Text,ignoreCase);
////			if(compared==0)
////			{
////				textBox.SelectedText=replaceWith.Text;
////			}
//		}
//		private void findNext_Click(object sender, System.EventArgs e)
//		{
//			AddComboBoxTextToItems(findWhat);
//			AddComboBoxTextToItems(replaceWith);
//			int foundPosition=Find();
//			if(foundPosition==-1)
//			{
//				ShowMessageBox("The specified text could not be found.");
//			}
//		}
    private void findNext_Click(object sender, System.EventArgs e)
    {
        //			if(findWhat.FindStringExact(findWhat.Text)==-1)
        //			{
        AddComboBoxTextToItems(findWhat);
        //findWhat.Items.Insert(0,findWhat.Text);
        //			}
        //			if(replaceWith.FindStringExact(replaceWith.Text)==-1)
        //			{
        AddComboBoxTextToItems(replaceWith);
        //replaceWith.Items.Insert(0,replaceWith.Text);
        //			}
        RichTextBoxFinds findOptions = RichTextBoxFinds.MatchCase;
        //			if(searchUp.Checked)
        //			{
        //				findOptions|=RichTextBoxFinds.Reverse;
        //			}
//			if(matchCase.Checked)
//			{
//				findOptions|=RichTextBoxFinds.MatchCase;
//			}
        int searchStart;

        //			if(searchUp.Checked)
        //			{
        //				searchStart=textBox.SelectionStart-1;
        //			}
        //			else
        //			{
        searchStart = textBox.SelectionStart + textBox.SelectionLength;
        //			}
        int findPosition = textBox.Text.IndexOf(findWhat.Text, searchStart);        //, findOptions);

        //int findPosition = textBox.Find(findWhat.Text, searchStart, findOptions);
        //int findPosition = textBox.Find(findWhat.Text, searchStart, findOptions);
        if (findPosition == -1)
        {
            //				if(searchUp.Checked)
            //				{
            //					searchStart=textBox.Text.Length;
            //				}
            //				else
            //				{
            searchStart = 0;
            //				}
            findPosition = textBox.Text.IndexOf(findWhat.Text, searchStart);            //, findOptions);
            //findPosition = textBox.Find(findWhat.Text, searchStart, findOptions);
            if (findPosition == -1)
            {
                ShowMessageBox("The specified text could not be found.");
            }
            //				MessageBox.Show("The specified text could not be found.");
        }
        if (findPosition != -1)
        {
            textBox.SelectionStart  = findPosition;           // = textBox.Find(findWhat.Text, textBox.SelectionStart, RichTextBoxFinds.None);
            textBox.SelectionLength = findWhat.Text.Length;
        }
    }
Exemplo n.º 27
0
 /// <summary>
 /// Searches the text in the control for a string with specific options applied to the search.
 /// </summary>
 /// <param name="str">The text to locate in the control.</param>
 /// <param name="start">The location within the control's text at which to begin searching.</param>
 /// <param name="options">A bitwise combination of the control values.</param>
 /// <returns>The location within the control where the search text was found.</returns>
 public int Find(string str, int start, RichTextBoxFinds options)
 {
     if (T == null)
     {
         return(0);
     }
     return(T.Find(str, start, options));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Search going down
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">An EventArgs that contains no event data.</param>
 private void downDirectionRadio_CheckedChanged(object sender, EventArgs e)
 {
     if (downDirectionRadio.Checked)
     {
         upOrDown = RichTextBoxFinds.None;
         startPosition = endPosition;
         endPosition = -1;
     }
 }
Exemplo n.º 29
0
 /// <summary>
 /// Search going up
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">An EventArgs that contains no event data.</param>
 private void upDirectionRadio_CheckedChanged(object sender, EventArgs e)
 {
     if (upDirectionRadio.Checked)
     {
         upOrDown      = RichTextBoxFinds.Reverse;
         endPosition   = startPosition;
         startPosition = 0;
     }
 }
Exemplo n.º 30
0
 /// <summary>
 /// Search going down
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">An EventArgs that contains no event data.</param>
 private void downDirectionRadio_CheckedChanged(object sender, EventArgs e)
 {
     if (downDirectionRadio.Checked)
     {
         upOrDown      = RichTextBoxFinds.None;
         startPosition = endPosition;
         endPosition   = -1;
     }
 }
Exemplo n.º 31
0
 public FindStatus()
 {
     this._MatchCase = false;
     this._BoxFinds = RichTextBoxFinds.None;
     this._SelectedString = string.Empty;
     this._StartIndex = 0;
     this._EndIndex = 0;
     this._WholeWord = false;
     this._Reverse = false;
 }
Exemplo n.º 32
0
 /// <summary>
 /// Constructor for findbox class,
 /// </summary>
 /// <param name="box">the text box which the find box will search</param>
 public FindBox(RichTextBox box)
 {
     InitializeComponent();
     dataBox = box;
     endPosition = -1;
     upOrDown = RichTextBoxFinds.None;
     matchCase = RichTextBoxFinds.None;
     matchWord = RichTextBoxFinds.None;
     mainStrings = new ResourceManager(typeof(Properties.Resources));
 }
Exemplo n.º 33
0
 public FindStatus(bool matchCase, RichTextBoxFinds boxFinds, string selectedString, int startIndex, int endIndex, bool wholeWord, bool reverse)
 {
     this._MatchCase = matchCase;
     this._BoxFinds = boxFinds;
     this._SelectedString = selectedString;
     this._StartIndex = startIndex;
     this._EndIndex = endIndex;
     this._WholeWord = wholeWord;
     this._Reverse = reverse;
 }
Exemplo n.º 34
0
 public FindStatus(FindStatus status)
 {
     this._MatchCase = status.MatchCase;
     this._BoxFinds = status.BoxFinds;
     this._SelectedString = status.SelectedString;
     this._StartIndex = status.StartIndex;
     this._EndIndex = status.EndIndex;
     this._WholeWord = status.WholeWord;
     this._Reverse = status.Reverse;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Constructor for findbox class,
 /// </summary>
 /// <param name="box">the text box which the find box will search</param>
 public FindBox(RichTextBox box)
 {
     InitializeComponent();
     dataBox     = box;
     endPosition = -1;
     upOrDown    = RichTextBoxFinds.None;
     matchCase   = RichTextBoxFinds.None;
     matchWord   = RichTextBoxFinds.None;
     mainStrings = new ResourceManager(typeof(Properties.Resources));
 }
Exemplo n.º 36
0
 private void ModifyOptions(bool isFlagPresent, RichTextBoxFinds option)
 {
     if (isFlagPresent)
     {
         _findOptions |= option;
     }
     else
     {
         _findOptions &= ~option;
     }
 }
Exemplo n.º 37
0
 /// <summary>
 /// Recursive function to find and mark each match
 /// </summary>
 /// <param name="start">Start index in RichTextBox to search</param>
 /// <param name="matches">Matches found</param>
 int Find(int start, RichTextBoxFinds richTextBoxFinds)
 {
     if (richTextBox.Find(textBox.Text, start, richTextBoxFinds) > -1)
     {
         richTextBox.SelectionBackColor = Color.Gold;
         return richTextBox.SelectionStart + richTextBox.SelectionLength < richTextBox.Text.Length ?
             Find(richTextBox.SelectionStart + richTextBox.SelectionLength, richTextBoxFinds) + 1
             : 1;
     }
     return 0;
 }
Exemplo n.º 38
0
 /// <summary>
 /// Recursive function to find and mark each match
 /// </summary>
 /// <param name="start">Start index in RichTextBox to search</param>
 /// <param name="matches">Matches found</param>
 int Find(int start, RichTextBoxFinds richTextBoxFinds)
 {
     if (richTextBox.Find(textBox.Text, start, richTextBoxFinds) > -1)
     {
         richTextBox.SelectionBackColor = Color.Gold;
         return(richTextBox.SelectionStart + richTextBox.SelectionLength < richTextBox.Text.Length ?
                Find(richTextBox.SelectionStart + richTextBox.SelectionLength, richTextBoxFinds) + 1
             : 1);
     }
     return(0);
 }
 /// <summary>
 /// Finds the first occurence of the specified string within the document if it exists.
 /// </summary>
 /// <param name="Txt">The string to find.</param>
 /// <param name="StartLoc">The position within the document to begin searching.</param>
 /// <param name="EndLoc">The position within the document to end searching.</param>
 /// <param name="Flags">Flags telling the document how to conduct its search.</param>
 /// <param name="Result">The location within the document of the supplied text.</param>
 /// <returns>True if the text was found.</returns>
 public bool Find(string Txt, TextLocation StartLoc, TextLocation EndLoc, RichTextBoxFinds Flags, out FindResult Result)
 {
     if ((Flags & RichTextBoxFinds.Reverse) == RichTextBoxFinds.Reverse)
     {
         return(FindReverse(Txt, ref StartLoc, ref EndLoc, Flags, out Result));
     }
     else
     {
         return(FindForward(Txt, ref StartLoc, ref EndLoc, Flags, out Result));
     }
 }
Exemplo n.º 40
0
 private void btnFindNext_Click(object sender, System.EventArgs e)
 {
     RichTextBoxFinds rtf = new RichTextBoxFinds();
     if(chWholeword.Checked)
         rtf |= RichTextBoxFinds.WholeWord;
     if(chCase.Checked)
         rtf |= RichTextBoxFinds.MatchCase;
     int p = rtb.Find(txtFind.Text,rtb.SelectionStart + rtb.SelectionLength, rtb.MaxLength, rtf);
     if(p == -1)
         DevExpress.XtraEditors.XtraMessageBox.Show("Không tìm thấy.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Exemplo n.º 41
0
        public int Find(string word, RichTextBoxFinds option = default(RichTextBoxFinds), int start = -1)
        {
            if (start != -1)
            {
                currentIdx = start;
            }
            int idx = richTextBox.Find(word, currentIdx, option);

            currentIdx = idx + 1;
            return(idx);
        }
Exemplo n.º 42
0
 private void Find()
 {
     RichTextBoxFinds options = new RichTextBoxFinds();
     if (chkWholeWords.Checked)
     {
         options = options | RichTextBoxFinds.WholeWord;
     }
     if (chkCase.Checked)
     {
         options = options | RichTextBoxFinds.MatchCase;
     }
     if (rdoUp.Checked)
     {
         options = options | RichTextBoxFinds.Reverse;
     }
     parent.Find(txtFind.Text, options);
 }
Exemplo n.º 43
0
    public static int Find (String Text, int Index, RichTextBoxFinds Flags)
    { if (TabManager.HasTabs ())
      { RichTextBox Box = TabManager.GetBox () ;

        Index = Box.Find (Text, Index, Flags) ;

        if (Index != -1)
        { Box.SelectionStart = Index ;
          Box.SelectionLength = Text.Length ;
          Box.HideSelection = false ;
        }
      }
      else
      { Index = -1 ;
      }

      return Index ;
    }
Exemplo n.º 44
0
 public void VervangAlles(string zoekText, string vervangText, RichTextBoxFinds rtbF)
 {
     //Zoek alles, zolang de index niet -1 is hebben we iets gevonden
     while (ZoekPositie != -1)
     {
         //Zolang onze zoek positie niet de lente van de zoektext is kunnen we zoeken, anders zitten we aan t einde en geven we een -1
         if (ZoekPositie != rtbZoek.Text.Length && ZoekPositie <= rtbZoek.Text.Length)
         {
             ZoekPositie = rtbZoek.Find(zoekText, ZoekPositie, rtbZoek.Text.Length, rtbF);
         }
         else
         {
             ZoekPositie = -1;
         }
         //Als onze index niet -1 is hebben we iets gevonden, de index heeft dan het nummer van de start positie van het woord
         if (ZoekPositie != -1)
         {
             //Selecteer dit woord vanaf de ZoekPositie(start) tot en met de lengte van onze zoektext
             rtbZoek.Select(ZoekPositie, zoekText.Length);
             //We hebben de tekst die vervangen moet worden geselecteerd, replace
             rtbZoek.SelectedText.Replace(rtbZoek.SelectedText, vervangText);
             //Zorg ervoor dat we alles wat voor onze zoek positie stond bewaard blijft
             string SubSone = rtbZoek.Text.Substring(0, ZoekPositie);
             //Haal alle text na onze zoekpositie op
             string SubStwo = rtbZoek.Text.Substring(ZoekPositie + zoekText.Length);
             //Voeg de tekst voor, + de vervangende tekst + de tekst erna samen
             rtbZoek.Text = SubSone + vervangText + SubStwo;
             //Zorg ervoor dat onze ZoekPositie vermeerderd word
             ZoekPositie += zoekText.Length;
         }
         else
         {
             Gevonden = false;
         }
     }
     //We zijn uit de loop, nu kunnen we onze zoekpositie weer op 0 zetten
     ZoekPositie = 0;
 }
Exemplo n.º 45
0
		// This version does not build one big string for searching, instead it handles 
		// line-boundaries, which is faster and less memory intensive
		// FIXME - Depending on culture stuff we might have to create a big string and use culturespecific 
		// search stuff and change it to accept and return positions instead of Markers (which would match 
		// RichTextBox behaviour better but would be inconsistent with the rest of TextControl)
		internal bool Find(string search, Marker start, Marker end, out Marker result, RichTextBoxFinds options) {
			Marker	last;
			string	search_string;
			Line	line;
			int	line_no;
			int	pos;
			int	line_len;
			int	current;
			bool	word;
			bool	word_option;
			bool	ignore_case;
			bool	reverse;
			char	c;

			result = new Marker();
			word_option = ((options & RichTextBoxFinds.WholeWord) != 0);
			ignore_case = ((options & RichTextBoxFinds.MatchCase) == 0);
			reverse = ((options & RichTextBoxFinds.Reverse) != 0);

			line = start.line;
			line_no = start.line.line_no;
			pos = start.pos;
			current = 0;

			// Prep our search string, lowercasing it if we do case-independent matching
			if (ignore_case) {
				StringBuilder	sb;
				sb = new StringBuilder(search);
				for (int i = 0; i < sb.Length; i++) {
					sb[i] = Char.ToLower(sb[i]);
				}
				search_string = sb.ToString();
			} else {
				search_string = search;
			}

			// We need to check if the character before our start position is a wordbreak
			if (word_option) {
				if (line_no == 1) {
					if ((pos == 0) || (IsWordSeparator(line.text[pos - 1]))) {
						word = true;
					} else {
						word = false;
					}
				} else {
					if (pos > 0) {
						if (IsWordSeparator(line.text[pos - 1])) {
							word = true;
						} else {
							word = false;
						}
					} else {
						// Need to check the end of the previous line
						Line	prev_line;

						prev_line = GetLine(line_no - 1);
						if (prev_line.ending == LineEnding.Wrap) {
							if (IsWordSeparator(prev_line.text[prev_line.text.Length - 1])) {
								word = true;
							} else {
								word = false;
							}
						} else {
							word = true;
						}
					}
				}
			} else {
				word = false;
			}

			// To avoid duplication of this loop with reverse logic, we search
			// through the document, remembering the last match and when returning
			// report that last remembered match

			last = new Marker();
			last.height = -1;	// Abused - we use it to track change

			while (line_no <= end.line.line_no) {
				if (line_no != end.line.line_no) {
					line_len = line.text.Length;
				} else {
					line_len = end.pos;
				}

				while (pos < line_len) {

					if (word_option && (current == search_string.Length)) {
						if (IsWordSeparator(line.text[pos])) {
							if (!reverse) {
								goto FindFound;
							} else {
								last = result;
								current = 0;
							}
						} else {
							current = 0;
						}
					}

					if (ignore_case) {
						c = Char.ToLower(line.text[pos]);
					} else {
						c = line.text[pos];
					}

					if (c == search_string[current]) {
						
						if (current == 0) {
							result.line = line;
							result.pos = pos;
						}
						if (!word_option || (word_option && (word || (current > 0)))) {
							current++;
						}

						if (!word_option && (current == search_string.Length)) {
							if (!reverse) {
								goto FindFound;
							} else {
								last = result;
								current = 0;
							}
						}
					} else {
						current = 0;
					}
					pos++;

					if (!word_option) {
						continue;
					}

					if (IsWordSeparator(c)) {
						word = true;
					} else {
						word = false;
					}
				}

				if (word_option) {
					// Mark that we just saw a word boundary
					if (line.ending != LineEnding.Wrap || line.line_no == lines - 1) {
						word = true;
					}

					if (current == search_string.Length) {
						if (word) {
							if (!reverse) {
								goto FindFound;
							} else {
								last = result;
								current = 0;
							}
						} else {
							current = 0;
						}
					}
				}

				pos = 0;
				line_no++;
				line = GetLine(line_no);
			}

			if (reverse) {
				if (last.height != -1) {
					result = last;
					return true;
				}
			}

			return false;

			FindFound:
			if (!reverse) {
//				if ((line.line_no == end.line.line_no) && (pos >= end.pos)) {
//					return false;
//				}
				return true;
			}

			result = last;
			return true;

		}
Exemplo n.º 46
0
        /// <summary>
        /// Handles the Click event of the Edit Replace menu item
        /// </summary>
        /// <param name="sender">Object that fired the event</param>
        /// <param name="e">.NET supplied event parameters</param>
        private void mnuEditReplace_Click(object sender, EventArgs e)
        {
            if (codeText.TextLength > 0)
            {
                int location = codeText.SelectionStart;
                string text = codeText.SelectedText;
                ReplaceDialog dlg = new ReplaceDialog(text);

                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    currentSearchOpts = (RichTextBoxFinds)0;
                    currentSearchString = dlg.ReplaceString;

                    if (dlg.CaseSensitive)
                    {
                        currentSearchOpts |= RichTextBoxFinds.MatchCase;
                    }

                    currentSearchOpts |= (dlg.WholeWord) ? RichTextBoxFinds.WholeWord : RichTextBoxFinds.None;

                    do
                    {
                        location = codeText.Find(currentSearchString, currentSearchOpts);

                        if (location > 0)
                        {
                            codeText.SelectionStart = location;
                            codeText.SelectionLength = currentSearchString.Length;
                            codeText.SelectedText = dlg.ReplacementString;
                        }
                    }
                    while (location > 0 && dlg.ReplaceAll);
                }
            }
            else
            {
                StatusTextBox.Text = SharedStrings.NO_SEARCH_TEXT;
            }
        }
        /// <summary>
        /// Searches for a string in the reverse direction of <see cref="FindForward"/>.
        /// </summary>
        /// <param name="Txt">The text to search for.</param>
        /// <param name="StartLoc">The starting location of the search.</param>
        /// <param name="EndLoc">The ending location of the search.</param>
        /// <param name="Flags">Flags controlling how the searching is conducted.</param>
        /// <param name="Result">Receives the results of the search.</param>
        /// <returns>True if a match was found.</returns>
        private bool FindReverse(string Txt, ref TextLocation StartLoc, ref TextLocation EndLoc, RichTextBoxFinds Flags, out FindResult Result)
        {
            bool bFound = false;
            bool bMatchWord;
            bool bIsWord;
            StringComparison ComparisonFlags;

            SetupFindState(Txt, ref StartLoc, ref EndLoc, Flags, out Result, out bIsWord, out ComparisonFlags, out bMatchWord);

            for(int CurLineIndex = StartLoc.Line; CurLineIndex >= EndLoc.Line && !bFound; --CurLineIndex)
            {
                if(GetLineLength(CurLineIndex) == 0)
                {
                    continue;
                }

                DocumentLine CurLineBldr = mLines[CurLineIndex];
                string LineTxt;
                int ColumnIndex = 0;

                if(CurLineIndex == StartLoc.Line && StartLoc.Column < GetLineLength(CurLineIndex))
                {
                    LineTxt = CurLineBldr.ToString(0, StartLoc.Column);
                }
                else if(CurLineIndex == EndLoc.Line && EndLoc.Column > 0)
                {
                    LineTxt = CurLineBldr.ToString(EndLoc.Column, CurLineBldr.Length - EndLoc.Column);
                    ColumnIndex = EndLoc.Column;
                }
                else
                {
                    LineTxt = CurLineBldr.ToString();
                }

                int Index = LineTxt.LastIndexOf(Txt, ComparisonFlags);

                if(Index != -1)
                {
                    ColumnIndex += Index;
                    CheckForWholeWord(Txt, ref Result, bMatchWord, ref bFound, bIsWord, CurLineIndex, CurLineBldr, ColumnIndex, Index);
                }
            }

            return bFound;
        }
        /// <summary>
        /// Performs general housekeeping for setting up a search.
        /// </summary>
        /// <param name="Txt">The text to search for.</param>
        /// <param name="StartLoc">The location to begin searching from.</param>
        /// <param name="EndLoc">The location to stop searching at.</param>
        /// <param name="Flags">Flags controlling how the search is performed.</param>
        /// <param name="Result">Receives the resulting location if a match is found.</param>
        /// <param name="bIsWord">Set to true if <paramref name="Txt"/> is a valid word.</param>
        /// <param name="ComparisonFlags">Receives flags controlling how strings are compared.</param>
        /// <param name="bMatchWord">Is set to true if only full words are to be matched.</param>
        private void SetupFindState(string Txt, ref TextLocation StartLoc, ref TextLocation EndLoc, RichTextBoxFinds Flags, out FindResult Result, out bool bIsWord, out StringComparison ComparisonFlags, out bool bMatchWord)
        {
            Result = FindResult.Empty;

            if(!IsValidTextLocation(StartLoc))
            {
                throw new ArgumentException("StartLoc is an invalid text location!");
            }

            if(!IsValidTextLocation(EndLoc))
            {
                throw new ArgumentException("EndLoc is an invalid text location!");
            }

            if((Flags & RichTextBoxFinds.Reverse) == RichTextBoxFinds.Reverse)
            {
                if(StartLoc < EndLoc)
                {
                    throw new ArgumentException("StartLoc must be greater than EndLoc when doing a reverse search!");
                }
            }
            else
            {
                if(StartLoc > EndLoc)
                {
                    throw new ArgumentException("StartLoc must be less than EndLoc when doing a forward search!");
                }
            }

            bMatchWord = (Flags & RichTextBoxFinds.WholeWord) == RichTextBoxFinds.WholeWord;
            bIsWord = IsWord(0, Txt);
            ComparisonFlags = StringComparison.OrdinalIgnoreCase;

            if((Flags & RichTextBoxFinds.MatchCase) == RichTextBoxFinds.MatchCase)
            {
                ComparisonFlags = StringComparison.Ordinal;
            }
        }
Exemplo n.º 49
0
 /// <summary>
 /// Handles the Click event of the Edit Find menu item
 /// </summary>
 /// <param name="sender">Object that fired the event</param>
 /// <param name="e">.NET supplied event parameters</param>
 private void mnuEditFind_Click(object sender, EventArgs e)
 {
     StatusTextBox.Clear();
     if (codeText.TextLength > 0)
     {
         SearchDialog dlg = new SearchDialog(codeText.SelectedText);
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             currentSearchString = dlg.SearchString;
             int currentPos = codeText.SelectionStart;
             currentSearchOpts = (RichTextBoxFinds)0;
             if (dlg.SearchDirection == SearchDialog.Direction.Beginning)
             {
                 codeText.SelectionStart = 0;
             }
             else if (dlg.SearchDirection == SearchDialog.Direction.Backward)
             {
                 currentSearchOpts |= RichTextBoxFinds.Reverse;
             }
             if (dlg.CaseSensitive)
             {
                 currentSearchOpts |= RichTextBoxFinds.MatchCase;
             }
             currentSearchOpts |= (dlg.WholeWord) ? RichTextBoxFinds.WholeWord : RichTextBoxFinds.None;
             int location = 0;
             if (codeText.TextLength > codeText.SelectionStart)
             {
                 location = codeText.Find(dlg.SearchString, codeText.SelectionStart, currentSearchOpts);
             }
             if (location > 0)
             {
                 codeText.SelectionStart = location;
                 codeText.SelectionLength = currentSearchString.Length;
             }
             else
             {
                 StatusTextBox.Text = SharedStrings.EOF;
                 codeText.SelectionStart = currentPos;
                 codeText.SelectionLength = 0;
             }
         }
     }
     else
     {
         StatusTextBox.Text = SharedStrings.NO_SEARCH_TEXT;
     }
 }
Exemplo n.º 50
0
	public int Find(String str, int start, int end, RichTextBoxFinds options)
	{
		throw new NotImplementedException("Find");
	}
Exemplo n.º 51
0
 /// <summary>
 /// Searches the text in a RichTextBox control for a string with specific options applied to the search.
 /// </summary>
 /// <param name="str">The text to locate in the control.</param>
 /// <param name="options">A bitwise combination of the RichTextBoxFinds values.</param>
 /// <returns>The location within the control where the search text was found.</returns>
 public int Find(string str, RichTextBoxFinds options)
 {
     return _richTextBox.Find(str, options);
 }
Exemplo n.º 52
0
		public int Find(string str, int start, RichTextBoxFinds options) {
			return Find(str, start, -1, options);
		}
Exemplo n.º 53
0
		public int Find(string str, RichTextBoxFinds options) {
			return Find(str, -1, -1, options);
		}
 /// <summary>
 /// Finds the first occurence of the specified string within the document if it exists.
 /// </summary>
 /// <param name="Txt">The string to find.</param>
 /// <param name="StartLoc">The position within the document to begin searching.</param>
 /// <param name="EndLoc">The position within the document to end searching.</param>
 /// <param name="Flags">Flags telling the document how to conduct its search.</param>
 /// <param name="Result">The location within the document of the supplied text.</param>
 /// <returns>True if the text was found.</returns>
 public bool Find(string Txt, TextLocation StartLoc, TextLocation EndLoc, RichTextBoxFinds Flags, out FindResult Result)
 {
     if((Flags & RichTextBoxFinds.Reverse) == RichTextBoxFinds.Reverse)
     {
         return FindReverse(Txt, ref StartLoc, ref EndLoc, Flags, out Result);
     }
     else
     {
         return FindForward(Txt, ref StartLoc, ref EndLoc, Flags, out Result);
     }
 }
Exemplo n.º 55
0
		public int Find(string str, int start, int end, RichTextBoxFinds options) {
			Document.Marker	start_mark;
			Document.Marker end_mark;
			Document.Marker result;

			if (start == -1) {
				document.GetMarker(out start_mark, true);
			} else {
				Line line;
				LineTag tag;
				int pos;

				start_mark = new Document.Marker();

				document.CharIndexToLineTag(start, out line, out tag, out pos);

				start_mark.line = line;
				start_mark.tag = tag;
				start_mark.pos = pos;
			}

			if (end == -1) {
				document.GetMarker(out end_mark, false);
			} else {
				Line line;
				LineTag tag;
				int pos;

				end_mark = new Document.Marker();

				document.CharIndexToLineTag(end, out line, out tag, out pos);

				end_mark.line = line;
				end_mark.tag = tag;
				end_mark.pos = pos;
			}

			if (document.Find(str, start_mark, end_mark, out result, options)) {
				return document.LineTagToCharIndex(result.line, result.pos);
			}

			return -1;
		}
Exemplo n.º 56
0
 protected void ReplaceAll(object sender, System.EventArgs e)
 {
     RichTextBoxFinds options = new RichTextBoxFinds();
     searchWordOnly = ((Replace)sender).SearchWordOnly;
     searchUpperLowerCase = ((Replace)sender).SearchUpperLowerCase;
     if (searchWordOnly) options |= RichTextBoxFinds.WholeWord;
     if (searchUpperLowerCase) options |= RichTextBoxFinds.MatchCase;
     searchText = ((Replace)sender).SearchText;
     replaceText = ((Replace)sender).ReplaceText;
     int startPos = 0;
     while (this.rtbMscEditor.Find(searchText,startPos ,options)!=-1){
         this.rtbMscEditor.SelectedText = replaceText;
         startPos = this.rtbMscEditor.SelectionStart + this.replaceText.Length;
     }
 }
Exemplo n.º 57
0
 private void SearchReplaceAgain(object sender, System.EventArgs e)
 {
     RichTextBoxFinds options = new RichTextBoxFinds();
     if (searchWordOnly) options |= RichTextBoxFinds.WholeWord;
     if (searchUpperLowerCase) options |= RichTextBoxFinds.MatchCase;
     if ((this.rtbMscEditor.Find(searchText,this.rtbMscEditor.SelectionStart + Math.Min(searchText.Length, this.rtbMscEditor.SelectionLength), options)==-1)&&(this.rtbMscEditor.SelectionStart + Math.Min(searchText.Length, this.rtbMscEditor.SelectionLength) > 0)){
         if(this.rtbMscEditor.Find(searchText,0 ,options)==-1){
             MessageBox.Show(strings.GetString("FileNotFound"));
         }
     }
 }
Exemplo n.º 58
0
 public void Find(string pSearchString, RichTextBoxFinds pFindOptions)
 {
     SearchString = pSearchString;
     FindOptions = pFindOptions;
     Find();
 }
Exemplo n.º 59
0
 /// <summary>
 /// Searches the text in a RichTextBox control for a string within a range of text within the control and with specific options applied to the search.
 /// </summary>
 /// <param name="str">The text to locate in the control.</param>
 /// <param name="start">The location within the control's text at which to begin searching.</param>
 /// <param name="end">The location within the control's text at which to end searching. This value must be equal to negative one (-1) or greater than or equal to the start parameter.</param>
 /// <param name="options">A bitwise combination of the RichTextBoxFinds values.</param>
 /// <returns></returns>
 public int Find(string str, int start, int end, RichTextBoxFinds options)
 {
     return _richTextBox.Find(str, start, end, options);
 }
Exemplo n.º 60
-9
        public void Vervang(string zoekText, string vervangText, RichTextBoxFinds rtbF)
        {
            //Zolang onze zoek positie niet de lente van de zoektext is kunnen we zoeken, anders zitten we aan t einde en geven we een -1
            if (ZoekPositie != rtbZoek.Text.Length && ZoekPositie <= rtbZoek.Text.Length)
            {
                ZoekPositie = rtbZoek.Find(zoekText, ZoekPositie, rtbZoek.Text.Length, rtbF);
            }
            else
                ZoekPositie = -1;

            //Als onze index niet -1 is hebben we iets gevonden, de index heeft dan het nummer van de start positie van het woord
            if (ZoekPositie != -1)
            {
                //Selecteer dit woord vanaf de ZoekPositie(start) tot en met de lengte van onze zoektext
                rtbZoek.Select(ZoekPositie, zoekText.Length);
                //ZoekPositie += zoekText.Length;
                string SubSone = rtbZoek.Text.Substring(0, ZoekPositie);
                string SubStwo = rtbZoek.Text.Substring(ZoekPositie + zoekText.Length);
                rtbZoek.Text = SubSone + vervangText + SubStwo;
                //Zorg ervoor dat onze ZoekPositie vermeerderd word
                ZoekPositie += zoekText.Length;
            }
            else
            {
                MessageBox.Show(string.Format("Kan {0} niet vinden", zoekText));
                ZoekPositie = 0;
                Gevonden = false;
            }
        }