5 Replies - 2649 Views - Last Post: 28 May 2011 - 08:01 AM Rate Topic: -----

#1 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Getting the XY of WPF RichTextBox caret

Posted 28 May 2011 - 06:46 AM

Hello everyone. I am in middle of implementing AutoComplete for a RichTextBox. Unfortunately, I have hit a snag in my line. I cannot seem to find a way to get the XY coordinates of the caret. I need this because I want to make the autocomplete window show up next to the caret.

I have been googling for the last two days. All of the results talk about the TextPointer and is not what I need.

EDIT: If it helps, this is my latest attempt.
//thw is the autocomplete window and box is the richtextbox.
thw.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
                    Rect bounds = box.CaretPosition.GetCharacterRect(LogicalDirection.Forward);
                    thw.Top = bounds.Y + box.Margin.Top + win.Top;
                    thw.Left = bounds.X + box.Margin.Left + win.Left;
                    thw.Show();


This post has been edited by Amrykid: 28 May 2011 - 06:58 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Getting the XY of WPF RichTextBox caret

#2 MATTtheSEAHAWK  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: Getting the XY of WPF RichTextBox caret

Posted 28 May 2011 - 07:10 AM

Well if your box variable is the RichTextBox then I couldn't find CaretPosition in intellisense. You should use box.GetPositionFromCharIndex(index); where index is the index of the char that you currently have. I'm not exactly sure how you would get the index but if I find out I will update this post with the how-to.

EDIT: I saw this but ignored it. Use int index = box.SelectionStar;. It does what the property says but if there is no selection then it gets the position of the caret as an offset from the beginning of the richTextBox. Good luck :)

This post has been edited by MATTtheSEAHAWK: 28 May 2011 - 07:13 AM

Was This Post Helpful? 0
  • +
  • -

#3 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Getting the XY of WPF RichTextBox caret

Posted 28 May 2011 - 07:28 AM

Thanks for the speedy reply, but you are thinking about the Winforms RichTextBox. I am using the WPF RichTextBox.

This post has been edited by Amrykid: 28 May 2011 - 07:28 AM

Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Getting the XY of WPF RichTextBox caret

Posted 28 May 2011 - 07:45 AM

View PostAmrykid, on 28 May 2011 - 10:28 AM, said:

Thanks for the speedy reply, but you are thinking about the Winforms RichTextBox. I am using the WPF RichTextBox.


We have a WPF forum for this exact reason.
Was This Post Helpful? 0
  • +
  • -

#5 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Getting the XY of WPF RichTextBox caret

Posted 28 May 2011 - 07:50 AM

Heh, I thought that was for XAML. My problem is using actual code. :online2long:

Thank you for moving it though.

This post has been edited by Amrykid: 28 May 2011 - 07:52 AM

Was This Post Helpful? 0
  • +
  • -

#6 MATTtheSEAHAWK  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: Getting the XY of WPF RichTextBox caret

Posted 28 May 2011 - 08:01 AM

Sorry I didn't know :(. I don't know much about WPF so the only thing I could find is an article on stackoverflow which is here and it looks like you have already tried it: http://stackoverflow...wpf-richtextbox
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1