Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How-To set Height of a Textbox?

Tags:

c#

winforms

For my single line Textbox, I set is Border = None. On doing this, the height turns very small. I can't programamtically set the height of the textbox. If I set any border, then again its fine, but I don't want any border. Even the text is not visible completely - so the font size is already bigger the the textbox height.

I tried creating a custom textbox, and set the Height of it, but it has no effect. How to handle this situation? Any help is highly appreciated.

like image 425
Tvd Avatar asked Dec 01 '22 02:12

Tvd


2 Answers

There is a simple way not to create a new class. In Designer.cs file:

this.textBox1.AutoSize = false;
this.textBox1.Size = new System.Drawing.Size(228, 25);

And that's all.

like image 145
Sereban Avatar answered Dec 04 '22 21:12

Sereban


TextBox derives from Control, which has an AutoSize property, but the designers have hidden the property from the PropertyGrid and Intellisense, but you can still access it:

public class TextBoxWithHeight : TextBox {

  public TextBoxWithHeight() {
    base.AutoSize = false;
  }
}

Rebuild and use.

like image 24
LarsTech Avatar answered Dec 04 '22 22:12

LarsTech