Airhead Airhead - 2 months ago 30
C# Question

Don't highlight newline characters when selecting with TextPointers

So, I have a

(shown below) which has a monospaced font, and must have the same number of characters on each line. Doing this requires inserting a
newline character after every
characters in the string that feeds the box.

I also have an algorithm that allows the cursor to move around with the press of the arrow keys, selecting individual characters as it moves. When the cursor covers a word in the box though, it should highlight the whole word.

Problem: When a word spans mutliple lines, there is an empty space following the final character of the first line, which I assume is caused by the

How can I make the
not highlight these blank spaces?
I can strip the selection of the character when parsing and such, but I need to be able to not highlight this blank space.

EDIT: An acceptable alternative would be making the newlines uneccessary. As in, to somehow fix the
so that it has always 12 characters on each line, but this is not ideal since I'd like to keep it easy to resize the window.

UPDATE: It seems that decreasing the width of the text column within the XAML has decreased the size of the highlight that goes over the edge, but has not eliminated it completely. I cannot decrease the width any more without causing text to wrap.

Example of Problem


I have figured out that the problem is not specifically related to the \n character.

I'm still not entirely sure what caused it, but I fixed it like this:

After playing around and noticing that changing the width of the column had an effect on the width of the bad highlighted area, I tried decreasing it away. Problem was, this caused text to wrap.

So I figured, okay, I'll just disable WordWrap for the RichTextBox, right? Wrong. WPF does not allow us to disable this.

I needed a way to achieve the effect of disabling WordWrap, so after doing some reading, I saw that I could set the FlowDocument's Width property to a very large number so that the text would never wrap. Even to do this, I then had to go and disable the scroll bar.

So then, I had the effect of wordwrap disabled and I was able to continue decreasing the width of the RichTextBox until the bad space was invisible, if not gone.

So, problem solved, but I'm still left with one question: Why does Microsoft hate me?