Increase TextBox height without increasing font size

I have a UserControl in my application and a TextBox is installed on it with the Docking.Fill property

I have a situation where I dynamically increase the size of windows / forms, in this case all my controls get the size in accordance with the new ratio, but the height of my text field does not change.

Solution 1: I have to set the font size to increase the height, but the problem is that it resizes all the controls that are used in my application, and also some text in the controls overlaps.

I need another way that does not affect the font size, I can grow my TextBox to Height without using Multiline = True .

It would be great if someone helped,

+3
source share
2 answers

you can do it in the constructor file

this.textBox1.AutoSize = false;
this.textBox1.Size = new System.Drawing.Size(100, 20);

MSDN> TextBoxBase.AutoSize Property

+2
source

A custom function that resizes a font with a compression ratio and increases the height of the TextBox.

public void IncerseHeightTextBox(TextBox tb, float Aspect_Ratio_Height)
    {
        tb.AutoSize = false;
        tb.Width = (int)(tb.Width * (1.402+1.171)/2); //Width+height Ratio /2
        tb.Font = new Font(tb.Font.FontFamily, tb.Font.Size * Aspect_Ratio_Height);
        tb.Size = new Size(tb.Width, (int)(tb.Height * Aspect_Ratio_Height));
    }

And the function call here:

IncerseHeightTextBox(tb2, (float)1.171);
+2
source

All Articles