예제 #1
0
        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            if (_textBox == null || (string.IsNullOrEmpty(_textBox.SelectedText) &&
                                     _textBox.GetCharacterIndexFromPoint(e.GetPosition(_textBox), false) > -1))
            {
                RoutedEventArgs args = new RoutedEventArgs(ClickedEvent, this);

                Dispatcher.BeginInvoke(new Action(() =>
                {
                    RaiseEvent(args);
                }), DispatcherPriority.ContextIdle);
            }

            base.OnPreviewMouseLeftButtonUp(e);
        }
예제 #2
0
 private static bool PlaceCaretOnTextBox(TextBox textBox, Point position)
 {
     int characterIndexFromPoint = textBox.GetCharacterIndexFromPoint(position, false);
     if (characterIndexFromPoint >= 0)
     {
         textBox.Select(characterIndexFromPoint, 0);
         return true;
     }
     return false;
 }
        // Token: 0x060049BB RID: 18875 RVA: 0x0014D824 File Offset: 0x0014BA24
        private static bool PlaceCaretOnTextBox(TextBox textBox, Point position)
        {
            int characterIndexFromPoint = textBox.GetCharacterIndexFromPoint(position, false);

            if (characterIndexFromPoint >= 0)
            {
                textBox.Select(characterIndexFromPoint, 0);
                return(true);
            }
            return(false);
        }
		private static int GetCaretIndexFromPoint(TextBox textBox, Point point)
		{
			var index = textBox.GetCharacterIndexFromPoint(point, true);

			if (index != textBox.Text.Length - 1)
				return index;

			var caretRect = textBox.GetRectFromCharacterIndex(index);
			var caretPoint = new Point(caretRect.X, caretRect.Y);

			if (point.X > caretPoint.X)
				index += 1;

			return index;
		}
        // This method is to workaround the fact that textbox.GetCharacterIndexFromPoint returns the caret
        // to the left of the character... Thus you can never get the caret after the last character in the
        // expression string.
        int GetCharacterIndexFromPoint(TextBox textbox)
        {
            Point position = Mouse.GetPosition(textbox);
            int index = textbox.GetCharacterIndexFromPoint(position, false);

            if (index < 0)
            {
                // May have clicked outside the text area, get the index of nearest char
                index = textbox.GetCharacterIndexFromPoint(position, true);
                if (index < 0)
                {
                    index = 0;
                }

                // Adjust the cursor position if we clicked to the right of returned character
                Rect charRect = textbox.GetRectFromCharacterIndex(index, true);
                if (position.X > charRect.Left + charRect.Width / 2)
                {
                    index++;
                }
            }

            return index;
        }