vb.net 更改文本框字体大小保持文本框大小(高度)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15853295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change TextBox font size keeping textBox size (Height)
提问by Anna Riekic
How can I change the font size of a TextBox but keep the TextBox height?
如何更改 TextBox 的字体大小但保持 TextBox 高度?
At the moment each time I try to change the font size the TextBox height re-sizes based on the font size, I sort of got it to work by changing the TextBox to multiline but only want a single line Textbox.
目前,每次我尝试更改字体大小时,TextBox 高度都会根据字体大小重新调整大小,我通过将 TextBox 更改为多行来使其工作,但只想要单行文本框。
回答by Anna Riekic
The textbox control has a hidden AutoSize property which can be disabled
文本框控件有一个隐藏的 AutoSize 属性,可以禁用
textBox1.AutoSize = False
textBox1.Height = 50
which I added to foo_load, you do end up with a large box and small font and looks a little odd due to textbox not having any padding property but this can be rectified by putting a panel behind it and positioning the textbox just inside.
我添加到 foo_load 中,你最终会得到一个大框和小字体,并且由于文本框没有任何填充属性而看起来有点奇怪,但这可以通过在它后面放置一个面板并将文本框定位在里面来纠正。
回答by Olivier Jacot-Descombes
In WinForms you can set the MinimumSizeand/or the MaximumSizeproperties of the TextBox in order to override the automatic adjustment of the TextBox height, when the font height changes.
在 WinForms 中,您可以设置TextBox的MinimumSize和/或MaximumSize属性,以便在字体高度更改时覆盖 TextBox 高度的自动调整。
Note that setting the minimum and maximum size does not change the TextBox size immediately. But when you change the width of the TextBox in the form designer, its height will be changed to be within the specified limits.
请注意,设置最小和最大大小不会立即更改 TextBox 大小。但是当您在表单设计器中更改 TextBox 的宽度时,其高度将更改为在指定范围内。

