[英]How to change the font style of text
How can I change the Font Style (regular, bold, etc) ? 如何更改字体样式(常规,粗体等)?
So far what I have is this: 到目前为止,我所拥有的是:
if (listBox1.SelectedIndex == 3)
{
if (textBox1.Text == "regular")
{
//FontStyle regular = new FontStyle !!!wrong one!!!
}
}
So what i need is that when I'd type "regular" in the textbox, the font style will change to regular. 所以我需要的是,当我在文本框中键入“ regular”时,字体样式将更改为“ regular”。 How do I do that?
我怎么做?
You need to set the Control.FontWeight property 您需要设置Control.FontWeight属性
if (listBox1.SelectedIndex == 3)
{
if (textBox1.Text == "regular")
{
TextBox1.FontWeight = FontWeights.Regular;
}
}
您是否正在寻找这样的东西:
textBox1.Font = new Font(textBox1.Font, FontStyle.Bold);
You need to create a new Font and apply it to your text box: 您需要创建一个新字体并将其应用于您的文本框:
textBox1.Font = new Font(FontFamily.GenericSansSerif, 12.0F, FontStyle.Normal);
This will create one with a new family etc. You can read the size and family from the existing Font object to preserve those. 这将创建一个带有新族的类,您可以从现有的Font对象中读取大小和族以保留它们。
textBox1.Font = new Font(textBox1.Font, FontStyle.Normal);
For more information on the properties of the Font class see the MSDN page 有关Font类的属性的更多信息,请参见MSDN页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.