2010-06-30 16 views

Antwort

18

Instanzen von Font sind unveränderlich. Sie müssen ein neues Font konstruieren und es der Font Eigenschaft zuweisen. Die Font Klasse hat verschiedene Konstruktoren für diesen Zweck; Sie kopieren eine andere Instanz und ändern dabei den Stil.

+11

+1 Und nur um die große Antwort zu vervollständigen: btnSizeRandom.Font = new Font (btnSizeRandom.Font, FontStyle.Bold); – SwDevMan81

+0

@ SwDevMan81 Zusätzlich benötigen Sie: neues system.Drawing.Font (btnSizeRandom.Font, FontStyle.Regular); – Recipe

11
private static Font ChangeBoldStyle(Font org, bool bold) { 
     FontStyle style = org.Style; 
     if (bold) style |= FontStyle.Bold; 
     else style &= ~FontStyle.Bold; 
     return new Font(org, style); 
    }