使用带有WPF标签的System.Drawing.Font [英] Using a System.Drawing.Font with a WPF Label

查看:175
本文介绍了使用带有WPF标签的System.Drawing.Font的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF Label控件,我试图改变使用由一些遗留代码提供的System.Drawing.Font对象的外观。我已经能够设置大部分的属性,但我正在挣扎Strikeout和下划线。

I have a WPF Label control which I'm trying to change the appearance of using a System.Drawing.Font object supplied by some legacy code. I have been able to set most of the properties, but am struggling with Strikeout and Underline.

到目前为止,我有:

So far I have:

System.Drawing.Font font = FontFromLegacyCode();

System.Windows.Controls.Label label = new System.Windows.Controls.Label();
label.FontFamily = new System.Windows.Media.FontFamily( font.Name );
label.FontWeight = font.Bold ? System.Windows.FontWeights.Bold : System.Windows.FontWeights.Regular;
label.FontStyle = font.Italic ? System.Windows.FontStyles.Italic : System.Windows.FontStyles.Normal;
label.FontSize = font.Size;

你如何设置字体删除或下划线属性?有没有更好的控制使用?

How do you set the font strikeout or underline properties? Is there a better control to use?

推荐答案

我会将其更改为TextBlock控件。 TextBlock控件具有您可以使用的TextDecorations属性。

I would change it to a TextBlock control. The TextBlock control has the TextDecorations property you can use.

<TextBlock Name="textBlock" TextDecorations="Underline, Strikethrough" />

如果你真的喜欢,也可以在一个标签内粘贴一个TextBlock(尽管我只是使用TextBlock本身)。

Or you can stick a TextBlock inside a Label if you really like (although I'd just use the TextBlock by itself).

<Label Name="label">
    <TextBlock Name="textBlock" TextDecorations="Underline, Strikethrough" />
</Label>

查看 TextDecorations class。

我发现TextBlocks比标签在大多数情况下。以下是关于差异的博客文章。主要区别在于Label是一个控件,而TextBlock只是一个FrameworkElement。另外一个标签支持访问键。

I find that TextBlocks are more suitable than Labels in most situations. Here's a blog post about the differences. The chief difference being that a Label is a Control whereas a TextBlock is just a FrameworkElement. Also a Label supports access keys.

这篇关于使用带有WPF标签的System.Drawing.Font的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆