DareDevil
DareDevil

Reputation: 5349

Increasing TextBox Height without Increasing Font Size

I have a UserControl in my Application and a TextBox is fitted on it with property Docking.Fill

I have a situation where I dynamically grow the windows/Forms size ,in that case all my controls get re-sized as per the new ratio, but my text box's height doesn't change.

Solution 1: I have to set the Font Size to increase height , but the issue is, It re-sizes all the controls which are used in my application, also some text in controls overlaps.

I want other way that without affecting the Font Size, i can grow my TextBox in Height without using Multiline = True.

It would be great if any body help,

Upvotes: 4

Views: 1948

Answers (2)

DareDevil
DareDevil

Reputation: 5349

A Custom Function which re-sizes the Font with a Aspect Ratio and Increase the height of 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 Function call here:

IncerseHeightTextBox(tb2, (float)1.171);

Upvotes: 2

Pranay Rana
Pranay Rana

Reputation: 176886

you can do this in designer file

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

MSDN > TextBoxBase.AutoSize Property

Upvotes: 4

Related Questions