Change the Textbox height?

后端 未结 21 2268
心在旅途
心在旅途 2020-12-09 07:24

How do I change the height of a textbox ?

Neither of the below work:

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


        
21条回答
  •  余生分开走
    2020-12-09 07:56

    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.

提交回复
热议问题