//最大程度的让windows窗体应用程序上的控件适合不同的分辨率
private void Form1_Resize(object sender, EventArgs e)
{
// 取得屏幕分辨率,宽 高
System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
rect = Screen.GetWorkingArea(this);
int width = rect.Width;
int height = rect.Height;
// 定位第一个标签,上面流出标题等内容的宽度
label1.Top = 260;
label1.Left = 200;
// 后续标签距离第一个标签的高度是:(屏幕高度 - 其余固定控件所需高度)/竖直摆放标签控件个数
label2.Top = label1.Top + (height - 300) / 5;
label2.Left = label1.Left;
label3.Top = label2.Top + (height - 300) / 5;
label3.Left = label1.Left;
label4.Top = label3.Top + (height - 300) / 5;
label4.Left = label1.Left;
label5.Top = label4.Top + (height - 300) / 5;
label5.Left = label1.Left;
label6.Top = label1.Top;
label6.Left = label1.Left+(width-300)/2;
label7.Top = label6.Top + (height - 300) / 5;
label7.Left = label6.Left;
label8.Top = label7.Top + (height - 300) / 5;
label8.Left = label6.Left;
label9.Top = label8.Top + (height - 300) / 5;
label9.Left = label6.Left;
label10.Top = label9.Top + (height - 300) / 5;
label10.Left = label6.Left;
pictureBox1.Width = width;
pictureBox1.Height = height + 46;
pictureBox1.Left = 0;
pictureBox1.Top = 0;
}
C#让windows窗体应用程序上的控件适合不同的分辨率
最新推荐文章于 2024-06-07 08:59:18 发布