①这是我之前用VS2015编译好的程序,直接运行没有问题
②这是里面Form的代码(控件大小随窗体变化而变化)
private float X;
private float Y;
private void setTag(Control cons)
{
foreach (Control con in cons.Controls)
{
con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
if (con.Controls.Count > 0)
setTag(con);
}
}
private void setControls(float newx, float newy, Control cons)
{
foreach (Control con in cons.Controls)
{
string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
float a = Convert.ToSingle(mytag[0]) * newx;
con.Width = (int)a;
a = Convert.ToSingle(mytag[1]) * newy;
con.Height = (int)a;
a = Convert.ToSingle(mytag[2]) * newx;
con.Left = (int)a;
a = Convert.ToSingle(mytag[3]) * newy;
con.Top = (int)a;
Single currentSize = Convert.ToSingle(mytag[4]) * Math.Min(newx, newy);
con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
if (con.Controls.Count > 0)
{
setControls(newx, newy, con);
}
}
}
private void Form15_Resize(object sender, EventArgs e)
{
float newx = (this.Width) / X;
float newy = (this.Height) / Y;
setControls(newx, newy, this);
this.Text = this.Width.ToString() + "" + this.Height.ToString();
}
private void Form15_Load(object sender, EventArgs e)
{
this.Resize += new EventHandler(Form15_Resize);
X = this.Width;
Y = this.Height;
setTag(this);
this.textBox1.Text = "0°0′0.000″";
this.textBox2.Text = "0°0′0.000″";
this.textBox3.Text = "0.00";
this.textBox4.Text = "0.00";
this.textBox5.Text = "0-00-00 00:00:00";
timer3.Enabled = true;
timer3.Start();
timer4.Enabled = true;
timer4.Start();
timer5.Enabled = true;
timer5.Start();
}
③现在只要单独运行这个Form15就报错
namespace BDEH
{
static class Program
{
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form15());
}
}
}
④这是报错的界面
之前以为是换电脑重装VS的原因,可是后来排查了几天,换了电脑系统也是一一样,真是奇怪了。而且我专门又建了一个项目,只运行这段代码,也是不行。求高手解答
图上不是有吗,con.Tag null