Hello all,
I'm currently implementing a text editor which needs to be able to handle non-breaking spaces .(  / ).
My problem is that we need to copy&paste pre-existing MS Word content into the TextBox (or RichTextBox). However, the non-breaking space was lost somewhere between copying from Word and inserting it into my textbox.
Have any of you encountered this problem? If so, did you figure out what to do about it?
I'm thinking that maybe I'm overlooking something really obvious here ...
Anyway, the following is the code I used to look at the pasted text.
private void PasteHandler(object sender, DataObjectPastingEventArgs e)
{
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText);
if (!isText) return;
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
string t = "";
foreach (char c in text.ToCharArray())
{
if (c == (char)160)
{
}
else
{
t += c;
}
}
}
What I have tried:
Well, I've looked at the content of the SourceDataObject of the DataObjectPastingEventArgs, specifically at the char values of the pasted text.
When I paste text from Word, all I get are regular spaces (32) instead of non-breaking spaces (160).
When I enter a non-breaking space into the textbox (alt + 0160) and I copy and paste this character, the non-breaking space is preserved.
I've also tried changing the DataFormat to no avail.
Thanks in advance for any help/hints
I also looked at the content of the clipboard directly but it's the same thing (not that I was really expecting otherwise).