question

AustinK-6056 avatar image
0 Votes"
AustinK-6056 asked Viorel-1 answered

WPF .NET Framework How do i get the line index or line height of a character?

I am making an app that will tell you what changed between two texts- it compares them. I want it to highlight the differences in a yellow box around the characters, but.. I can't figure out how to get the height of the line the characters are in. So the overall question here is how do I find the line index or height of a character in a TextBox.

windows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

For example, to get the rectangle of the third character:

 var r1 = textBox1.GetRectFromCharacterIndex( 3, false );
 var r2 = textBox1.GetRectFromCharacterIndex( 3, true );
 var result = Rect.Union( r1, r2 );

Then you can obtain the width and height.

You can also get the rectangle of a range (word) if the characters are not placed on different lines.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.