Winforms:组合框高度在分辨率更改时不调整
我在表单中有一个基本组合框。与其他控件(按钮,标签等)相比,分辨率更改时,组合框的高度不会改变。Winforms:组合框高度在分辨率更改时不调整
public partial class Form1 : Form {
string result;
string fontInformation;
private bool scaleFactorKnown = false;
private SizeF scaleFactor;
public Form1()
{
SizeChanged += Form1_SizeChanged;
InitializeComponent();
label1.Location = new Point(12, 36);
label1.Size = new Size(100, 21);
label1.Scale(scaleFactor);
//
// textBox1
//
textBox1.Location = new Point(133, 33);
textBox1.Size = new Size(100, 21);
textBox1.Scale(scaleFactor);
//
// comboBox1
//
comboBox1.Location = new Point(250, 33);
comboBox1.Size = new Size(100, 21);
comboBox1.Scale(scaleFactor);
// button1
//
button1.Location = new Point(365, 32);
button1.Size = new Size(100, 21);
button1.Scale(scaleFactor);
//
// radioButton1
//
radioButton1.Location = new Point(480, 32);
radioButton1.Size = new Size(100, 21);
radioButton1.Scale(scaleFactor);
//
// checkBox1
//
checkBox1.Location = new Point(586, 33);
checkBox1.Size = new Size(100, 21);
checkBox1.Scale(scaleFactor);
//
// textBox2
//
textBox2.Location = new Point(26, 102);
textBox2.Size = new Size(660, 250);
textBox2.Scale(scaleFactor);
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (!scaleFactorKnown)
{
scaleFactor = AutoScaleFactor;
scaleFactorKnown = true;
}
Size controlSize = new Size((int)(comboBox1.Width * scaleFactor.Width),
(int)(comboBox1.Height * scaleFactor.Height)); //use for sizing
//set bounds
comboBox1.Bounds = new Rectangle(comboBox1.Location, controlSize);
}
}
我曾尝试方法Scale()扩展所有其他控件,它为其他控件除了组合框。我也尝试手动更改绑定,但它没有工作。我也尝试改变锚和码头。
- 预期结果:组合框高度(在150%)= 42
- 实际结果:组合框 高度(在150%)= 28
希望得到关于如何解决这一问题的任何帮助。
回答:
您必须设置ComboBox
到false
的IntegralHeight
属性:
comboBox1.Location = new Point(250, 33); comboBox1.Size = new Size(100, 21);
comboBox1.Scale(scaleFactor);
comboBox1.IntegralHeight = false;
以上是 Winforms:组合框高度在分辨率更改时不调整 的全部内容, 来源链接: utcz.com/qa/261709.html