【问题标题】:Initialization Font Object with multiple style具有多种样式的初始化字体对象
【发布时间】:2013-07-31 02:51:00
【问题描述】:

我需要在运行时根据四个布尔值初始化具有多种样式的字体对象。

    bool bold,italic,underline,strikeout;

     myFont = new Font(fontText[0], size, FontStyle.Bold,FontStyle.Italic,FontStyle.Undeline,FontStyle.Strikeout);
//If all boolen values are true.

如果考虑布尔值的所有可能性,将有24种情况。

如何避免写所有这些条件? 建议一些方法来做到这一点?

【问题讨论】:

  • 给你:stackoverflow.com/questions/2813134/…顺便说一句,只有16箱。
  • @Mr.Lister 字体样式可能完全不存在所以 4*3*2*1 = 24;
  • 不,这不正确,抱歉。您不能以一种以上的方式组合字体样式。 FontStyle.Italic|FontStyle.BoldFontStyle.Bold|FontStyle.Italic 完全相同。我链接的问题有帮助吗?

标签: c#


【解决方案1】:

试试这个,我得到答复:

Font myFont;
myFont = new Font(fontName, fontSize, FontStyle.Bold|FontStyle.Italic|FontStyle.Undeline|FontStyle.Strikeout);  

例如:

Font myFont;
float fontSize=12;
string fontName="Arial";
bool bold=false,italic=false;
if(bold==true && italic==true)
myFont=new Font(fontName,fontSize,FontStyle.Bold|FontStyle.Italic);

【讨论】:

    猜你喜欢
    • 2021-09-11
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 2013-06-27
    • 2013-08-11
    • 1970-01-01
    相关资源
    最近更新 更多