I load font.size in a file that this format is string and i want to set textbox.font.size by this value but say "this value is readonly not set" how i can set font.size in coding?
-
2WinForms? WPF? ASP.NET? Please, add appropriate tag to your question. Also show what you have tried so far – Sergey Berezovskiy Nov 07 '13 at 11:22
-
http://stackoverflow.com/questions/10173147/easiest-way-to-change-font-and-font-size-with-visual-c-sharp – Tomaz Tekavec Nov 07 '13 at 11:25
5 Answers
By Using this it is possible to programmatically choose the best font. This also allows you to set different sizes on the various alternative fonts.
Font font = new Font("Times New Roman", 16.0f,
FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
textBox1.Font = font;
For more details, check here

- 6,730
- 4
- 25
- 35
You can Set the Font Property of TextBox Control.
Font Property of TextBox Control Expects Font Class Object.
you can create the Font class oject with different styles by passing different parameters to its constructors.
Font Class Constructor Description :
FontFamily - FontFamily (EnumType) : used to specify Font name ex:Arial,Times New Roman etc.,
FontSize - float(DataType) : it's a float value of font size.
FontStyle - FontStyle (EnumType) : it is a FontStyle of different types ex: FontStyle.Regular,FontStyle.Bold,FontStyle.Italic etc.,
Now See sample Example:
Font fnt=new Font(textBox1.Font.FontFamily,12.0F);//Edit your size asper your requirement. it's float value
textBox1.Font = fnt;

- 25,935
- 5
- 37
- 67
Create new font from current font (use it as prototype) and provide font size (parse your string to float):
textBox1.Font = new Font(textBox1.Font, Single.Parse(sizeString));

- 232,247
- 41
- 429
- 459
You have to set it at start of the Initialization of textbox
like
var textbox = new TextBox()
{
FontFamily = "Segoe WP",
FontSize = 18
};

- 42,633
- 14
- 77
- 146

- 2,597
- 1
- 16
- 28