private void MainTextBox_LostFocus(object sender, RoutedEventArgs e) { if (CurrentSelectingPosition != 0 && !string.IsNullOrEmpty(CurrentlySelectedText)) { MainTextBox.Select(CurrentSelectingPosition, CurrentlySelectedText.Length); } }
public AdvancedTextBox() { InitializeComponent(); LineNumbers.Font = MainTextBox.Font; MainTextBox.Select(); UpdateLineNumbers(); CreateSnapshot(); }
//public void FindAndSelect(string TextToFind, bool MatchCase) //{ // StringComparison mode = MatchCase ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; // // int position = MainTextBox.Text.IndexOf(TextToFind, mode); // // if (position == -1) // return; // // //MainTextBox.SelectionStart = position; // //MainTextBox.SelectionLength = TextToFind.Length; // CurrentSelectingPosition = position; // CurrentlySelectedText = TextToFind; // MainTextBox.Select(position, TextToFind.Length); //} public void FindAndSelect(string pSearchText, string totalText, bool pMatchCase, bool pSearchDown) { if (!ViewModel.FindWindow.HasAlreadySearched) { ViewModel.FindWindow.FoundTextIndexes = totalText.AllIndexesOf(pSearchText); ViewModel.FindWindow.HasAlreadySearched = true; } if (ViewModel.FindWindow.HasAlreadySearched) { //int firstIndex = MainTextBox.Text.ToLower().IndexOf(pSearchText); MainTextBox.Select(ViewModel.FindWindow.FoundTextIndexes[ViewModel.FindWindow.CurrentFindIndex], pSearchText.Length); int caretIndex = MainTextBox.CaretIndex; int before = caretIndex - pSearchText.Length - 8; int after = caretIndex + 8; if (before >= 0 && after + 8 < totalText.Length) { try { string charsBetweenWord = totalText.Substring(before, after); ViewModel.FindWindow.SetPreviewText(charsBetweenWord); } catch { } } ViewModel.FindWindow.CurrentFindIndex++; } //int Index; // //var eStringComparison = pMatchCase ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; // //// if (pSearchDown) ////{ // Index = MainTextBox.Text.IndexOf( // pSearchText, // MainTextBox.SelectionStart, // MainTextBox.Text.Length - MainTextBox.SelectionStart, // eStringComparison); ////} // //if (Index == -1) return; // //string _LastSearchText = pSearchText; //bool _LastMatchCase = pMatchCase; //bool _LastSearchDown = pSearchDown; // //MainTextBox.SelectionStart = Index; //MainTextBox.SelectionLength = pSearchText.Length; }
private void MainTextBox_MouseDown(object sender, MouseEventArgs e) { MainTextBox.Select(); LineNumbers.DeselectAll(); }
private void MainTextBox_FontChanged(object sender, EventArgs e) { LineNumbers.Font = MainTextBox.Font; MainTextBox.Select(); UpdateLineNumbers(); }
public void Select(int start, int length) { MainTextBox.Select(start, length); }