如何在运行时将文本框的文本设置为粗体? [英] How do I set a textbox's text to bold at run time?

查看:42
本文介绍了如何在运行时将文本框的文本设置为粗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Windows 表单,并且我有一个文本框,如果它是某个值,我偶尔会希望将文本设为粗体.

I'm using Windows forms and I have a textbox which I would occassionally like to make the text bold if it is a certain value.

如何在运行时更改字体特征?

How do I change the font characteristics at run time?

我看到有一个名为 textbox1.Font.Bold 的属性,但这是一个 Get only 属性.

I see that there is a property called textbox1.Font.Bold but this is a Get only property.

推荐答案

字体本身的粗体属性是只读的,但文本框的实际字体属性不是.您可以将文本框的字体更改为粗体,如下所示:

The bold property of the font itself is read only, but the actual font property of the text box is not. You can change the font of the textbox to bold as follows:

  textBox1.Font = new Font(textBox1.Font, FontStyle.Bold);

然后又回来:

  textBox1.Font = new Font(textBox1.Font, FontStyle.Regular);

这篇关于如何在运行时将文本框的文本设置为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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