以编程方式更改字体 [英] Change a font programmatically

查看:59
本文介绍了以编程方式更改字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#不喜欢以下代码:

C# doesn't like the following code:

private void btnSizeRandom_Click(object sender, EventArgs e)
{
  btnSizeRandom.Font.Bold = true;
  btnother.Font.Bold = false;
}

有没有办法以编程方式执行此操作?

Is there a way to do this programatically?

推荐答案

字体的实例是不可变的.您需要构造一个新的 Font 并将其分配给 Font 属性.为此, Font 类具有各种构造函数.他们复制另一个实例并在此过程中更改样式.

Instances of Font are immutable. You need to construct a new Font and assign it to the Font property. The Font class has various constructors for this purpose; they copy another instance and change the style in the process.

这篇关于以编程方式更改字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆