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

推荐订阅源

罗磊的独立博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
Y
Y Combinator Blog
雷峰网
雷峰网
Last Week in AI
Last Week in AI
Jina AI
Jina AI
月光博客
月光博客
G
Google Developers Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
H
Heimdal Security Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
AWS News Blog
AWS News Blog
NISL@THU
NISL@THU
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
P
Privacy International News Feed
I
Intezer
V
Vulnerabilities – Threatpost
The GitHub Blog
The GitHub Blog
L
LINUX DO - 最新话题
S
Schneier on Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
小众软件
小众软件
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
W
WeLiveSecurity
Security Latest
Security Latest
PCI Perspectives
PCI Perspectives
The Hacker News
The Hacker News
T
Threatpost
C
Check Point Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Latest news
Latest news
L
LINUX DO - 热门话题
J
Java Code Geeks
A
Arctic Wolf
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog

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