Wednesday, March 28, 2012

C# - Change TextBox Height with Multiline=False

// set the AutoSize property to false;

textBox1.AutoSize = false;

// what I would do is add another borderless textbox on top of textBox1,
// then add a textBox1.GotFocus handler that would execute the other textbox's focus() method.

here's what the MSVS 2005 .Net SDK says about the TextBoxBase (notice the red texts)

public abstract class TextBoxBase : Control
{
//
// Summary:
//  Gets or sets a value indicating whether the height of the control automatically
//  adjusts when the font assigned to the control is changed. This property is
//  not relevant for this class.
//
// Returns:
//  true if the height of the control automatically adjusts when the font is
//  changed; otherwise, false. The default is true.
[Localizable(true)]
[EditorBrowsable(1)]
[Browsable(false)]
[DefaultValue(true)]
[RefreshProperties(2)]
public override bool AutoSize { get; set; }