3

I would like it to form a tool change it at one of the characters in thickness (Bold), or underscore (Underline) during program run. I tried to set the next program code, but failed. I received the following error: "Property or indexer 'Font.Bold' can not be assigned to - it is read only"

Why can not I set this property?

((TextBox)tabControl1.Controls[S].Controls[K]).Font.Bold = true;
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
Juhász Lajos
  • 129
  • 1
  • 2
  • 8

1 Answers1

6

You cannot change existing font instance. You should create new font instance from one you have and assign it to textbox. E.g. if you only want to change font style, you can use Font(Font prototype, FontStyle newStyle) constructor:

var textBox = (TextBox)tabControl1.Controls[S].Controls[K];
textBox.Font = new Font(textBox.Font, FontStyle.Bold);
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459