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

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 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

    上面写了如何改变字体风格,下面再写一下如何改变字体大小?观察字体类时,你会发现它所提供的公共属性都是只读的.这就意味着改变一个字体大小,你需要创建一个新的并且带有和先前的字体有完全相同的属性除了字体大小的对象.这里恰好有这么一个方便的方法:

static public Font ChangeFontSize( Font font, float fontSize )
{
    
if (font != null)
    
{
        
float currentSize = font.Size;
        
if (currentSize != fontSize)
        
{
            font 
= new Font( font.Name, fontSize,
                font.Style, font.Unit,
                font.GdiCharSet, font.GdiVerticalFont );
        }

    }

    
return font;
}

举个例子,把一个标签字体放大2倍:

label.Font = ChangeFontSize( label.Font, label.Font.Size * 2 );

图形单位

注意以上的方法都使用了相同的图形单位(点,像素,毫米,等等),对于一个字体,你或许想"重载"这个方法而使用特定的单位:

static public Font ChangeFontSize( Font font, float fontSize, GraphicsUnit unit )
{
    
if (font != null)
    
{
        
float currentSize = font.Size;
        
if (currentSize != fontSize)
        
{
            font 
= new Font( font.Name, fontSize,
                font.Style, unit,
                font.GdiCharSet, font.GdiVerticalFont );
        }

    }

    
return font;
}

举个例子,把一个标签的字体设置为12像素:

label.Font = ChangeFontSize( label.Font, 12.0F, GraphicsUnit.Pixel );