I'm using Windows forms and I have a textbox which I would occassionally like to make the text bold if it is a certain value.
How do I change the font characteristics at run time?
I see that there is a property called textbox1.Font.Bold but this is a Get only property.
You could use
Extension
method to switch between Regular Style and Bold Style as below:And usage:
The bold property of the font itself is read only, but the actual font property of the text box is not. You can change the font of the textbox to bold as follows:
And then back again:
Depending on your application, you'll probably want to use that Font assignment either on text change or focus/unfocus of the textbox in question.
Here's a quick sample of what it could look like (empty form, with just a textbox. Font turns bold when the text reads 'bold', case-insensitive):