Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the Textbox height?

How do I change the height of a textbox ?

Neither of the below work:

this.TextBox1.Size = new System.Drawing.Size(173, 100); 

or

this.TextBox1.Size.Height = 100; 

I wanted to be able to change the single line text box height to fit a font size on it without using multi-line if possible.

like image 323
Guapo Avatar asked May 02 '11 02:05

Guapo


2 Answers

Go into yourForm.Designer.cs Scroll down to your textbox. Example below is for textBox2 object. Add this

this.textBox2.AutoSize = false; 

and set its size to whatever you want

this.textBox2.Size = new System.Drawing.Size(142, 27); 

Will work like a charm - without setting multiline to true, but only until you change any option in designer itself (you will have to set these 2 lines again). I think, this method is still better than multilining. I had a textbox for nickname in my app and with multiline, people sometimes accidentially wrote their names twice, like Thomas\nThomas (you saw only one in actual textbox line). With this solution, text is simply hiding to the left after each char too long for width, so its much safer for users, to put inputs.

like image 185
Tomasz Szymański Avatar answered Sep 18 '22 04:09

Tomasz Szymański


There are two ways to do this :

  • Set the textbox's "multiline" property to true, in this case you don't want to do it so;
  • Set a bigger font size to the textbox

I believe it is the only ways to do it; the bigger font size should automatically fit with the textbox

like image 24
MrRoy Avatar answered Sep 18 '22 04:09

MrRoy