i\'ve changed a WinForms TextBox
control to have no border.
When i do the bottom pixel row of text in the box is being cut off.
Top:
This seems to do the trick:
public Form2()
{
InitializeComponent();
textBox1.Multiline = true;
textBox1.MinimumSize = new Size(0, 30);
textBox1.Size = new Size(textBox1.Size.Width, 30);
textBox1.Multiline = false;
}
The AutoSize
property is there, just inherit from TextBox
and you can get to the property:
public class TextBoxEx : TextBox {
public TextBoxEx() {
base.AutoSize = false;
}
}
You can do this in your form:
private void RefreshHeight(TextBox textbox)
{
textbox.Multiline = true;
Size s = TextRenderer.MeasureText(textbox.Text, textbox.Font, Size.Empty, TextFormatFlags.TextBoxControl);
textbox.MinimumSize = new Size(0, s.Height + 1);
textbox.Multiline = false;
}
Then you say RefreshHeight(textbox1);
Multiline
change will force the textbox to "accept" the new size
You can also fix this in the Visual Studio Designer.
Change the height in the minimum size property for the text box. Change to multiline=true, then back to false. The text box will resize and stay fix.
No code changes needed.