Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property or indexer 'Font.Bold' can not be assigned to - it is read only [duplicate]

Tags:

c#

winforms

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;
like image 248
Juhász Lajos Avatar asked Sep 17 '25 14:09

Juhász Lajos


1 Answers

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);
like image 186
Sergey Berezovskiy Avatar answered Sep 20 '25 06:09

Sergey Berezovskiy