Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the position of the caret in a TextBox

Tags:

c#

.net

wpf

I need to know the position of the caret in a TextBox so I can pop up a context menu near it. How do I find its placement (not character index)?

like image 608
RandomEngy Avatar asked Jun 27 '09 20:06

RandomEngy


2 Answers

Found this article describing how to do what I need done. Turns out you can set both the PlacementTarget of the textbox and the PlacementRectangle from GetRectFromCharacterIndex and it will work.

like image 124
RandomEngy Avatar answered Sep 18 '22 22:09

RandomEngy


Check out this example.

like image 44
JP Alioto Avatar answered Sep 21 '22 22:09

JP Alioto