如何更改字体样式(常规,粗体等)?
到目前为止,我所拥有的是:
if (listBox1.SelectedIndex == 3)
{
if (textBox1.Text == "regular")
{
//FontStyle regular = new FontStyle !!!wrong one!!!
}
}
所以我需要的是当我在文本框中键入“常规”时,字体样式将变为常规。我该怎么做?
答案 0 :(得分:0)
您需要设置Control.FontWeight属性
if (listBox1.SelectedIndex == 3)
{
if (textBox1.Text == "regular")
{
TextBox1.FontWeight = FontWeights.Regular;
}
}
答案 1 :(得分:0)
你在寻找这样的东西:
textBox1.Font = new Font(textBox1.Font, FontStyle.Bold);
答案 2 :(得分:0)
您需要创建一个新字体并将其应用到文本框中:
textBox1.Font = new Font(FontFamily.GenericSansSerif, 12.0F, FontStyle.Normal);
这将创建一个新的系列等。您可以从现有的Font对象中读取大小和族,以保留它们。
textBox1.Font = new Font(textBox1.Font, FontStyle.Normal);
有关Font类属性的更多信息,请参阅the MSDN page