[求助] WPF FontFamily=“System” 不支持么?无法使用这个字体
wpf吧
全部回复
仅看楼主
level 1
FontFamily=“System” 不支持么?无法使用这个字体。[狂汗]
2013年12月27日 03点12分 1
level 7
不清楚你说的system是啥
给你写个demo也许有用
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="cbo_Demo" Margin="3" Width="180" SelectionChanged="cbo_Demo_SelectionChanged">
</ComboBox>
<TextBox Name="tb" Text="测试文字" Width="80" Height="25" Margin="5"></TextBox>
</StackPanel>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
foreach (FontFamily _f in Fonts.SystemFontFamilies)
{
LanguageSpecificStringDictionary _fontDic = _f.FamilyNames;
if (_fontDic.ContainsKey(XmlLanguage.GetLanguage("zh-cn")))
{
string _fontName = null;
if (_fontDic.TryGetValue(XmlLanguage.GetLanguage("zh-cn"), out _fontName))
{
var item = new ComboBoxItem();
var tempTb = new TextBlock()
{
Text = _fontName,
FontFamily = _f
};
item.Content = tempTb;
cbo_Demo.Items.Add(item);
}
}
}
cbo_Demo.SelectedIndex = 0;
}
private void cbo_Demo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = cbo_Demo.SelectedItem as ComboBoxItem;
var font = (item.Content as TextBlock).FontFamily;
this.tb.FontFamily = font;
}
2013年12月27日 05点12分 2
level 1
这个 demo 我试过,字体选择中没有 System 这个字体可供选择。
System 是个 windows 自带字体,在 C:\Windows\Fonts 文件夹中有
(System 字体文件名称 svgasys.fon)
2013年12月27日 06点12分 3
楼主问题解决了吗
2020年12月03日 02点12分
level 7
明白你的意思了.可以实现但稍麻烦些.
1 找到对应的字体文件,
我随便找的C:\Windows\Fonts\STHUPO.TTF,(这个是华文琥珀字体)
'然后把STHUPO.TTF拷贝到你项目文件夹下,
右键项目---添加现有项---把STHUPO.TTF加入到项目中,记得属性--生成操作设置为Resource
2
<Window.Resources>
<Style x:Key="myFont">
<Setter Property="TextElement.FontFamily" Value="#华文琥珀"/>
</Style>
</Window.Resources>
<TextBox Name="tb" Style="{StaticResource myFont}" FontSize="15" Text="自定义字体" Width="80" Height="55" Margin="5"></TextBox>
效果如下图
2013年12月27日 07点12分 4
不错呀!兄弟挺厉害!跟你混了!求qq!
2013年12月28日 07点12分
1