C# wpf不同的字体取决于同一句子中的语言
我想实现一个功能,用户可以选择两种字体。 一种字体是英文,另一种是汉字。 它类似于Microsoft word中的字体设置,就像下面的链接一样。 我知道wpf中有一种叫做复合字体的东西。但我需要让用户实时更改这两种语言的字体,就像MicrosoftWord一样。 我如何实现它?C# wpf不同的字体取决于同一句子中的语言,c#,wpf,fonts,C#,Wpf,Fonts,我想实现一个功能,用户可以选择两种字体。 一种字体是英文,另一种是汉字。 它类似于Microsoft word中的字体设置,就像下面的链接一样。 我知道wpf中有一种叫做复合字体的东西。但我需要让用户实时更改这两种语言的字体,就像MicrosoftWord一样。 我如何实现它? 谢谢 您可以使用RichTextBox控件执行此操作。请参阅以下代码 <StackPanel> <RichTextBox Width="100" Height="200" x:Name="tx
谢谢 您可以使用RichTextBox控件执行此操作。请参阅以下代码
<StackPanel>
<RichTextBox Width="100" Height="200" x:Name="txtRich"/>
<Button Content="Set Arial Font" Click="Button_Click"/>
<Button Content="Set Tahoma Font" Click="Button_Click_1"/>
</StackPanel>
private void Button_Click(object sender, RoutedEventArgs e)
{
if (!txtRich.Selection.IsEmpty)
{
TextRange selectionTextRange = new TextRange(txtRich.Selection.Start, txtRich.Selection.End);
selectionTextRange.ApplyPropertyValue(TextElement.FontFamilyProperty, new FontFamily("Arial"));
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (!txtRich.Selection.IsEmpty)
{
TextRange selectionTextRange = new TextRange(txtRich.Selection.Start, txtRich.Selection.End);
selectionTextRange.ApplyPropertyValue(TextElement.FontFamilyProperty, new FontFamily("Tahoma"));
}
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
如果(!txtRich.Selection.IsEmpty)
{
TextRange selectionTextRange=新的TextRange(txtRich.Selection.Start,txtRich.Selection.End);
selectionTextRange.ApplyPropertyValue(TextElement.FontFamilyProperty,新FontFamily(“Arial”);
}
}
私有无效按钮\u单击\u 1(对象发送者,路由目标)
{
如果(!txtRich.Selection.IsEmpty)
{
TextRange selectionTextRange=新的TextRange(txtRich.Selection.Start,txtRich.Selection.End);
selectionTextRange.ApplyPropertyValue(TextElement.FontFamilyProperty,新FontFamily(“Tahoma”);
}
}
我想让程序自动检测中文并为中文应用字体。如何实现自动检测中文并为中文应用字体?谢谢