//Method to search text according to direction and case public void SearchText() { var stringCompare = Check ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; if (SearchDown) { Index = TextInBox.IndexOf(TextToFind, SelectionEnd, stringCompare); } else { if (SelectionStart - 1 != -1) { Index = TextInBox.LastIndexOf(TextToFind, SelectionStart - 1, stringCompare); } else { MessageBox.Show("Cannot find \"" + TextToFind + "\".", "Notepad#"); } } if (Index == -1) { MessageBox.Show("Cannot find \"" + TextToFind + "\".", "Notepad#"); } else { SelectionStart = Index; SelectionEnd = Index + TextToFind.Length; note.rtbInput.SelectionStart = Index; note.rtbInput.SelectionLength = TextToFind.Length; note.rtbInput.Focus(); base.Show(); } }
//Replaces all occurences of selected text private void ReplaceAllText() { var stringCompare = Check ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; Index = TextInBox.IndexOf(TextToFind, SelectionEnd, stringCompare); if (Index == -1) { MessageBox.Show("Cannot find \"" + TextToFind + "\".", "Notepad#"); } else { note.rtbInput.Text = note.rtbInput.Text.Replace(TextToFind, TextToReplace); MessageBox.Show("All occurences replaced successfully.", "Notepad#"); TextInBox = note.rtbInput.Text; base.Show(); } }