I have 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;
Last line doesn't work, because .Color field cannot be found. Why?
Because a font does not have a color. A control can render text using a font and a color, but the color is not a property of the font.
EDIT:
If you want a textbox that uses a given font and color you can do the following (I'm assuming that you are using winforms):
var myTextBox = new TextBox();
myTextBox.ForeColor = col;
myTextBox.Font = birthdayFont;
myTextBox.Text = "Happy birthday!";
this.Controls.Add(myTextBox);
Fonts do not have colors. You use colors in the drawing code itself, or with the Control.ForeColor
property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With