如何在富文本框中插入unicode字符?

时间:2022-01-04 15:49:35

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.

我正在编写一个带有RichTextBox和工具栏的WPF应用程序(一个非常简单的RichText编辑器)。无论如何,我想在ToolBar中放入6个可以单击的unicode字符,并将插入到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

1 个解决方案

#1


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.

对于我来说,代码隐藏中的事件处理程序似乎是一种自然的方式。 Unicode字符在.NET中只是字符,因此它们可能在ASCII字符集之外的事实并不意味着任何额外的困难。

Something like this ought to do:

这样的事应该做​​:

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

#1


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.

对于我来说,代码隐藏中的事件处理程序似乎是一种自然的方式。 Unicode字符在.NET中只是字符,因此它们可能在ASCII字符集之外的事实并不意味着任何额外的困难。

Something like this ought to do:

这样的事应该做​​:

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