【发布时间】:2014-10-31 08:52:48
【问题描述】:
我在 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);
}
非常感谢您的回答
谢谢
【问题讨论】:
-
在设计时使用尽可能低的分辨率(在您的示例中为 1024x768)以确保控件不会重叠。
-
如果您不执行任何操作,控件将自动调整大小而不会重叠。还是您希望每个分辨率的尺寸保持不变?
-
分辨率在 1366 x 768 以上时尺寸保持不变,但如果分辨率低于 1366 x 768,则尺寸将自动调整大小以免相互重叠,先生@γηράσκωδ'αείπολλάδιδασκόμε
-
分辨率与重叠无关。 100 像素 文本框将始终 为 100 像素。改变的是
pixel的大小。当分辨率降低时,它会得到bigger。最终图像完全相同(没有重叠)但更大!你的SetComponents()函数导致了问题,这就是我说不要做任何事情的原因。我的意思是不要使用这个功能。