对于我的单行文本框,我将其边框设置为无。但这样做会使高度变得非常小。我无法以编程方式设置文本框的高度。如果我设置任何边框,那么一切都好了,但我不想要任何边框。甚至文本也无法完全显示 - 所以字体大小已经大于文本框高度。
我尝试创建自定义文本框,并设置其高度,但没有效果。如何处理这种情况?非常感谢您的帮助。
有一种简单的方法可以避免创建新类。 在Designer.cs文件中:
this.textBox1.AutoSize = false;
this.textBox1.Size = new System.Drawing.Size(228, 25);
这就是全部。
TextBox
继承自 Control
,后者具有一个名为 AutoSize 的属性,但设计师已将该属性从 PropertyGrid 和 Intellisense 中隐藏,但您仍然可以访问它:public class TextBoxWithHeight : TextBox {
public TextBoxWithHeight() {
base.AutoSize = false;
}
}
重新构建并使用。
TextBox
控件会根据其 Font
的高度自动调整大小,无论您选择的 BorderStyle
是什么。这是 Visual Studio 使用的默认值之一。
this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif",
26.25F,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
((byte)(0)));
this.textBox1.Location = new System.Drawing.Point(373, 502);
// this is what makes the height 'stick'
this.textBox1.Multiline = true;
// the desired height
this.textBox1.Size = new System.Drawing.Size(100, 60);
public class TextBoxWithHeight : TextBox
{
public bool Auto_Size
{
get { return this.AutoSize; }
set { this.AutoSize = value; }
}
}
只需选择你的文本框并进入属性,然后增加字体大小.. 完成!!!