public partial class Index : Form
{
//变量
float WL, HL;
bool bl = true;
public Index()
{
InitializeComponent();
//增加窗口变化事件
this.Resize += new EventHandler(formChange);
//初始界面大小
this.Size = new System.Drawing.Size(1300, 700);
WL = this.Width;
HL = this.Height;
//重绘控件
HL = this.Height - 40;
WL = this.Width - 18;
#region 界面控件
for (int i = 0; i < 4; i++)
{
string[] name = { "K", "S", "D", "X" };
string[] TEXT = { "1", "2", "3", "4" };
int W = (int)WL;
int H = (int)HL;
Button Pbut = new Button();
Pbut.Name = name[i];
Pbut.Text = TEXT[i];
Pbut.Font = new Font("宋体", 15f, FontStyle.Regular);
Pbut.BackColor = Color.Transparent;
if (i < 2)
{
Pbut.Location = new System.Drawing.Point(W * i / 2, 0);
}
else
{
Pbut.Location = new System.Drawing.Point(W * (i - 2) / 2, H / 2);
}
Pbut.Size = new System.Drawing.Size(W / 2, H / 2);
//鼠标移入
Pbut.MouseEnter += new EventHandler(PS_IN);
//鼠标移出
Pbut.MouseLeave += new EventHandler(PS_OUT);
//鼠标点击
Pbut.MouseDown += new MouseEventHandler(PS_Click);
//鼠标弹起
this.Controls.Add(Pbut);
#endregion
}
//调用窗口控件方法
conChange(this);
}
#region 获取控件信息方法
public void conChange(Control cons)
{
foreach (Control c in cons.Controls)
{
c.Tag = c.Width + ";" + c.Height + ";" + c.Left + ";" + c.Top + ";" + c.Font.Size;
if (c.Controls.Count > 0)
{
conChange(c);
}
}
}
#endregion
#region 重构控件大小方法
public void newCon(float newW, float newH, Control cons)
{
foreach (Control c in cons.Controls)
{
if (c.Tag != null)
{
string[] newTag = c.Tag.ToString().Split(new char[] { ';' });
c.Width = Convert.ToInt32(System.Convert.ToSingle(newTag[0]) * newW);//宽度
c.Height = Convert.ToInt32(System.Convert.ToSingle(newTag[1]) * newH);//高
c.Left = Convert.ToInt32(System.Convert.ToSingle(newTag[2]) * newW);//左
c.Top = Convert.ToInt32(System.Convert.ToSingle(newTag[3]) * newH);//上
Single currentSize = System.Convert.ToSingle(newTag[4]) * newH;//字体大小
c.Font = new Font(c.Font.Name, currentSize, c.Font.Style, c.Font.Unit);
if (c.Controls.Count > 0)
{
newCon(newW, newH, cons);
}
}
}
}
#endregion