[英]The size of the components resize with the screen resolution c#
我在winform中有5个文本框,分辨率为1366x768时,它们的位置和大小正确。 但是,一旦我将分辨率更改为1024x768,两个文本框就会相互重叠。
我的问题是:如何根据屏幕分辨率缩放文本框的宽度?
这是图像:
1366x768屏幕分辨率:
1024x768屏幕分辨率:
对于1024x768屏幕分辨率,此处的描述文本框与数量文本框重叠。
这是我正在使用的代码:
void SetComponents()
{
_screen = Screen.PrimaryScreen.WorkingArea;
this.label1.Text = "Product Code";
this.label1.Location = new Point(40, (_screen.Height - _screen.Height) + 125);
this.textBox1.Location = new Point(25, (_screen.Height - _screen.Height) + 150); // textbox for the product code
this.label2.Text = "Quantity";
this.label2.Location = new Point(215, (_screen.Height - _screen.Height) + 125);
this.numericUpDown1.Location = new Point(185, (_screen.Height - _screen.Height) + 150); // numeric up down for the quantity
this.label3.Text = "Description";
this.textBox2.Size = new Size((_screen.Width / 2) + 100, 20); // textbox for the description
this.label3.Location = new Point((_screen.Width / 2) + 50, (_screen.Height - _screen.Height) + 125);
this.textBox2.Location = new Point((_screen.Width / 2) - 325, (_screen.Height - _screen.Height) + 150); // textbox for the description
this.label4.Text = "Price (@ Rp)";
this.label4.Location = new Point((_screen.Width - 150), (_screen.Height - _screen.Height) + 125);
this.textBox3.Location = new Point((_screen.Width - 165), (_screen.Height - _screen.Height) + 150); // textbox for the price
this.label5.Text = "Date / Time: ";
this.textBox4.Size = new Size(145, 20); // textbox for the date / time
this.label5.Location = new Point((_screen.Width - 275), (_screen.Height - _screen.Height) + 58);
this.textBox4.Location = new Point((_screen.Width - 200), (_screen.Height - _screen.Height) + 55); // textbox for the date / time
this.label6.Text = _welcomeText + UserInformation.CurrentLoggedInUser + " - " + UserInformation.CurrentLoggedInUserType;
this.label6.Location = new Point((_screen.Width - _screen.Width) + 10, (_screen.Height - _screen.Height) + 30);
this.button1.Text = "Submit";
this.button1.Location = new Point((_screen.Width / 2) - 150, (_screen.Height - _screen.Height) + 185);
this.button2.Text = "Reset";
this.button2.Location = new Point((_screen.Width / 2) + 100, (_screen.Height - _screen.Height) + 185);
this.button3.Text = "Delete";
this.button3.Location = new Point((_screen.Width / 2) + 20, (_screen.Height - _screen.Height) + 185);
this.button4.Text = "Edit";
this.button4.Location = new Point((_screen.Width / 2) - 70, (_screen.Height - _screen.Height) + 185);
this.button5.Text = "Update";
this.button5.Location = new Point((_screen.Width / 2) - 70, (_screen.Height - _screen.Height) + 185);
this.button6.Text = "Cancel";
this.button6.Location = new Point((_screen.Width / 2) + 100, (_screen.Height - _screen.Height) + 185);
this.button7.Text = "Information";
this.button7.Location = new Point(10, (_screen.Height - _screen.Height) + 185);
this.dataGridView1.Size = new Size((_screen.Width) - 40, (_screen.Height - _screen.Height) + 460);
this.dataGridView1.Location = new Point((_screen.Width - _screen.Width) + 10, (_screen.Height - _screen.Height) + 225);
}
非常感谢您的回答
谢谢
通常的方法是使用winform TableControlLayout中的容器控件,然后将这些控件绑定到您的窗体上,将Fill属性。 在容器内,添加通常的控件,这些控件应对齐到容器并根据需要调整大小。
在您的情况下,您似乎正在使用填充表格整个底部的DataGridView,这应该是正确的。
在DataGridView列编辑器内,您可以按百分比,绝对值或告诉它们填充剩余空间的方式编辑每列的fill属性。
编辑:
好像我误解了你的问题。 无论如何,这都是关于Containers和Fill属性的
尝试这个:
ctl.Height = ctl.Height * (My.Computer.Screen.Bounds.Height / 768);
ctl.Width = ctl.Width * (My.Computer.Screen.Bounds.Width / 1366);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.