C # apply color to font

I have a code like this.

System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#101B83");
System.Drawing.Font nameFont = new System.Drawing.Font("Tahoma", 10);
System.Drawing.Font birthdayFont = new System.Drawing.Font("Tahoma", 6);
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
nameFont.Color = col;

The last line does not work, because the .Color field cannot be found. Why?

+5
source share
3 answers

Because the font has no color. A control can display text using font and color, but color is not a font property.

EDIT:

If you want to use a text box that uses the given font and color, you can do the following (I assume you are using winforms):

var myTextBox = new TextBox();
myTextBox.ForeColor = col;
myTextBox.Font = birthdayFont;
myTextBox.Text = "Happy birthday!";

this.Controls.Add(myTextBox);
+12
source

Fonts are colorless. You use colors in the drawing code itself or in the propertyControl.ForeColor

+2
source

ForeColor. . . forecolor .

+1

All Articles