将字体设置为斜体和粗体
如何将多种字体样式应用于文本?
System.Drawing.Font MyFont = new System.Drawing.Font(
thisTempLabel.LabelFont,
((float)thisTempLabel.fontSize),
FontStyle.Bold + FontStyle.Italic, // + obviously doesn't work, but what am I meant to do?
GraphicsUnit.Pixel
);
感谢您的帮助!
How do you apply multiple font styles to text?
System.Drawing.Font MyFont = new System.Drawing.Font(
thisTempLabel.LabelFont,
((float)thisTempLabel.fontSize),
FontStyle.Bold + FontStyle.Italic, // + obviously doesn't work, but what am I meant to do?
GraphicsUnit.Pixel
);
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许您想使用 OR 运算符 (
|
)Maybe you wanted to use the OR operator (
|
)FontStyle
是一个标志枚举,因此您可以通过以下方式设置多种样式:FontStyle
is a flag enum and therefore you can set multiple styles by:我认为这是 FontStyle.Bold | FontStyle.Italic
您通常使用管道(按位或)符号来组合这些函数中的多个标志
本页对此进行了解释
http://www.blackwasp.co.uk/CSharpLogicalBitwiseOps_2.aspx
I think it's FontStyle.Bold | FontStyle.Italic
You generally use the pipe (bitwise OR) symbol to combine multiple flags in these functions
This page explains it
http://www.blackwasp.co.uk/CSharpLogicalBitwiseOps_2.aspx
我认为您可以从 Font 类中受益:
I think you could benefit from a Font class:
嗨,我正在编写一个简单的文本编辑器,我遇到了同样的问题,我在互联网上没有找到任何有用的东西。如果表单中有很多按钮,则 if , else if 方法不是最佳的,所以我想为什么不采用现有的 font.style 并使用 | 添加到它中。像上面建议的那样的符号。我测试了这段代码并且它有效。我从单击的图片框调用此方法。
更新。我发现了一个错误。当您取消选择一种字体时,它也会将所有其他字体重置为常规字体。但将它们结合起来的代码是有效的。
PS 我使用图片框而不是按钮和布尔变量(如 BClicked)指示它们是否被激活。
Hi I was writing a simple Text Editor and I had the same problem, I didn't find anything helpful on the internet. The if , else if method isn't optimal if there are many buttons in the form, so I thought why not take the existing font.style and just add to it using | symbol like people suggested above. I tested this code and it works. I call this method from pictureBox I click.
Update. I found a bug. when you deselect a font, it resets all others to regular too. But the code that combines them works.
P.S I used picture boxes instead of buttons and boolean variables like BClicked indicate whether they are activated or not.