读书人

#中lable及其内容怎的随对话框的改变成

发布时间: 2013-10-11 14:52:39 作者: rapoo

#中lable及其内容怎样随对话框的改变成比例的改变
C#中lable及其内容怎样随对话框的改变成比例的改变,窗体中有四个lable控件,两行两列排列 对话框 c#
[解决办法]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
label1.AutoSize = false;
label1.Dock = DockStyle.Left;
label1.TextAlign = ContentAlignment.MiddleLeft;
label2.AutoSize = false;
label2.Dock = DockStyle.Right;
label2.TextAlign = ContentAlignment.MiddleRight;
label3.AutoSize = false;
label3.Dock = DockStyle.Top;
label3.TextAlign = ContentAlignment.TopCenter;
label4.AutoSize = false;
label4.Dock = DockStyle.Bottom;
label4.TextAlign = ContentAlignment.BottomCenter;
Label[] labels = { label1, label2, label3, label4 };
foreach (Label l in labels)
{
l.Font = new Font(l.Font.Name, this.Height / 15);
l.Size = new Size(Width / 3, Height / 3);
}
}

private void Form1_Resize(object sender, EventArgs e)
{
Label[] labels = { label1, label2, label3, label4 };
foreach (Label l in labels)
{
l.Font = new Font(l.Font.Name, this.Height / 15);
l.Size = new Size(Width / 3, Height / 3);
}
}
}
}


在界面上摆4个label,然后编写两个事件处理函数,如代码。
[解决办法]
好像可以用 tablelayoutpanel 来实现布局,和你要的需求

读书人网 >C#

热点推荐