Kyle West
Kyle West

Reputation: 9098

How to insert a unicode character in a rich text box?

I'm writing a WPF application with a RichTextBox and a Toolbar (a VERY simple RichText Editor). Anyway, I want to put 6 unicode characters in the ToolBar that can be clicked and will be inserted at whatever point to the RichTextBox.

This seems like something that should be fairly simple to do (without a lot of codebehind). Is it, or do I have to write some custom methods to make this happen?

Thanks,

Kyle

Upvotes: 1

Views: 3853

Answers (1)

PeterAllenWebb
PeterAllenWebb

Reputation: 10408

An event handler in the codebehind seems like the natural way to go, to me. Unicode characters are simply characters in .NET, so the fact that they may be outside the ASCII character set does not imply any additional difficulty.

Something like this ought to do:

private void button_Click(object sender, RoutedEventArgs e)
{
    MyRtb.CaretPosition.InsertTextInRun("む");
}

Upvotes: 2

Related Questions