如何改变字体风格?

    改变字体风格要比改变它的大小要容易一点,因为在字体的构造函数中可以传一个字体风格作为参数.举个例子:一个加粗的标签字体:
Label label  =   new  Label();
. . .
label.Font 
=   new  Font( label.Font, FontStyle.Bold );
   如果你想保持初始的风格并且加粗它:
   
    label.Font  =   new  Font( label.Font, label.Font.Style  |  FontStyle.Bold );
    上面的解决方法创建了一个新字体对象,不管需不需要!这儿有一个更方便的方法,加粗字体,仅当需要时才新创建一个字体对象:
   
static   public  Font BoldFont( Font font )
{
    
if (font != null)
    
{
        FontStyle fontStyle 
= font.Style;
        
if ((fontStyle & FontStyle.Bold) == 0)
        
{
            fontStyle 
|= FontStyle.Bold;
            font 
= new Font( font, fontStyle );
        }

    }

    
return font;
}
举个例子,加粗一个标签字体:
label.Font  =  BoldFont( label.Font );

转载于:https://www.cnblogs.com/yangjie5188/archive/2008/03/19/1112603.html

猜你喜欢

转载自blog.csdn.net/weixin_34162629/article/details/93499942