c# set FontSize of TextBox

85,155

You have to set the Font property. Size is a readonly property of Font.

var textBox = (TextBox)client.Controls[0];
textBox.Font = new Font(textBox.Font.FontFamily, 16);
Share:
85,155

Related videos on Youtube

Jordan Trainor
Author by

Jordan Trainor

Updated on November 24, 2020

Comments

  • Jordan Trainor
    Jordan Trainor over 3 years

    How would I set the font size of a TextBox in c#. I can get the current size but it does not allow to set it.

    public static Form client;
    ((TextBox)client.Controls[0]).Font.size = 16;
    
  • dajon
    dajon about 10 years
    so instead of: textBox.Font.Size *= 1.1f; to do: textBox.Font = new Font(textBox.Font.FontFamily, textBox.Font.Size*1.1f);
  • Shadi
    Shadi almost 4 years
    @dajon so, I have to save the textbox content and re-populate the new one? Do you know why they have not made it the easy way?