Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I use a RichTextBox in C# (.Net) where I need to replace each "*" and "+" by other Unicode chars (\u2605 and \u271A). It works fine, but the problem is when I copy content from MS Word and paste it to the RichTextBox, my two Unicode chars are replaced by "Square" ([]), not just for the pasted content but for all the content of my RichTextBox even if I reload the content from the database. I must close and re-execute my application to see my Unicode chars again.
Do you know how I could fix my problem, by an appropriate paste method or a way to reset the format of my RichTextBox ?

What I have tried:

void PasteAction(object sender, EventArgs e)
{
IDataObject data = Clipboard.GetDataObject();

if (data.GetDataPresent(DataFormats.Rtf))
{
selected = (String)data.GetData(DataFormats.Rtf);
}
else if (selected != String.Empty)
{
Clipboard.SetData(DataFormats.Rtf, selected);
}

richTextAgenda.SelectedRtf = selected;
}
Posted
Comments
Jochen Arndt 30-Aug-17 7:55am    
Don't know if this helps but you might try using
RichTextBox.Paste(DataFormats.Rtf);

instead which replaces the current selection with the RTF clipboard data (or inserts it at the current position if nothing is selected).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900