RichTextKit v0.4

Hit Testing

Hit testing lets you find the character cluster that a co-ordinate is either directly over and/or closest to. This can be used to be build a range selection feature and/or as part of a more comprehensive editor.

// Hit test a mouse co-ordinate for example
var htr = tb.HitTest(x, y);

The co-ordinates passed to the RichString.HitTest and TextBlock.HitTest methods must be relative to the top-left corner of the object. (ie: you'll probably need to adjust the co-ordinates by subtracting the top-left position of where you're displaying the text block).

The returned HitTestResult structure describes the line and code point cluster the point is either directly over and/or closest to.

Subscribe for more like this. No spam, just fun tech stuff :)

Or, find me on Twitter: @toptensoftware.