1

如何更改字体样式(常规、粗体等)?

到目前为止,我所拥有的是:

if (listBox1.SelectedIndex == 3)
{
   if (textBox1.Text == "regular")
   {
     //FontStyle regular = new FontStyle   !!!wrong one!!!
   }
}

所以我需要的是,当我在文本框中输入“常规”时,字体样式将变为常规。我怎么做?

4

3 回答 3

0

您需要设置Control.FontWeight属性

if (listBox1.SelectedIndex == 3)
{
      if (textBox1.Text == "regular")
      {         
          TextBox1.FontWeight = FontWeights.Regular;
      }
}
于 2013-10-12T14:57:06.357 回答
0

您是否正在寻找这样的东西:

textBox1.Font = new Font(textBox1.Font, FontStyle.Bold);
于 2013-10-12T14:57:25.673 回答
0

您需要创建一个新字体并将其应用于您的文本框:

textBox1.Font = new Font(FontFamily.GenericSansSerif, 12.0F, FontStyle.Normal);

这将创建一个具有新系列的系列等。您可以从现有的 Font 对象中读取大小和系列以保留它们。

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

有关 Font 类属性的更多信息,请参阅MSDN 页面

于 2013-10-12T14:57:34.783 回答