惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
G
Google Developers Blog
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
U
Unit 42
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Securelist
Schneier on Security
Schneier on Security
F
Full Disclosure
P
Proofpoint News Feed
C
Cisco Blogs
J
Java Code Geeks
K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
小众软件
小众软件
博客园_首页
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
阮一峰的网络日志
阮一峰的网络日志
W
WeLiveSecurity
AI
AI
V
V2EX
B
Blog RSS Feed
Google Online Security Blog
Google Online Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
腾讯CDC
P
Privacy & Cybersecurity Law Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
IT之家
IT之家
Latest news
Latest news
The GitHub Blog
The GitHub Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
爱范儿
爱范儿
Y
Y Combinator Blog
TaoSecurity Blog
TaoSecurity Blog
aimingoo的专栏
aimingoo的专栏
S
Secure Thoughts

博客园 - Lucky Jack

在C#中展示嵌入的RTF文件 SQL进行排序、分组、统计的10个新技巧 select into 和 insert into select的区别 Convert的妙用 DataGridView中回车键的妙用 如何去除C#Strings中的空格? Format String for XML Value - Lucky Jack 如何改变字体大小呢? C# String小技巧 如何避免按回车键时的嗡鸣声? - Lucky Jack - 博客园 如何嵌入图片资源? Lookupedit使用小记 如何优雅的编程? 文件监视器( FileSystemWatcher) 类的使用 - Lucky Jack 反射也可以这样? - Lucky Jack - 博客园 浅谈对象的初始化顺序 也谈String.IsNullOrEmpty 经典的属性设置! 经典sql
如何改变字体风格?
Lucky Jack · 2008-03-19 · via 博客园 - Lucky Jack

    改变字体风格要比改变它的大小要容易一点,因为在字体的构造函数中可以传一个字体风格作为参数.举个例子:一个加粗的标签字体:

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 );