0

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?

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
user2949651
  • 45
  • 1
  • 1
  • 4

5 Answers5

8

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

Gopesh Sharma
  • 6,730
  • 4
  • 25
  • 35
4

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;
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
1

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));
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
0

You have to set it at start of the Initialization of textbox

like

var textbox = new TextBox()
                  {
                     FontFamily = "Segoe WP",
                     FontSize = 18
                  };
Sayse
  • 42,633
  • 14
  • 77
  • 146
techloverr
  • 2,597
  • 1
  • 16
  • 28
-1

Font.Size is read only. You must set the Font object itself.

Sam Axe
  • 33,313
  • 9
  • 55
  • 89