2013-10-12 65 views
1

如何更改字體樣式(常規,粗體等)?如何更改文字的字體樣式

到目前爲止,我有什麼是這樣的:

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

所以,我需要的是,當我鍵入「正規」的文本框,字體風格,將改變規則。我怎麼做?

回答

0

您需要設置Control.FontWeight屬性

if (listBox1.SelectedIndex == 3) 
{ 
     if (textBox1.Text == "regular") 
     {   
      TextBox1.FontWeight = FontWeights.Regular; 
     } 
} 
0

您正在尋找這樣的事情:

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

你需要創建一個新的字體,並將其應用到您的文本框:

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

這將創建一個與新的家庭等您可以閱讀的大小和家庭從現有的Font對象來保存這些對象。

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

有關字體類的屬性的更多信息請參見the MSDN page