我有一个程序可以在我的计算机上获取系统信息,我希望它比较另一台计算机上的信息系统,如果参数相同,那么我写一条消息“匹配”,如果它们不是不一致,我的程序工作很好,当我使用下面这样的文本框时
private void button1_Click(object sender, EventArgs e)
{
System.OperatingSystem OS = System.Environment.OSVersion;
GetSystemInfo(ref n);
string processor;
switch (n.processorArchitecture)
{
case 0: processor = "Intel(x84)";
break;
case 9: processor = "AMD or Intel (x64)";
break;
default: processor = "Unknown";
break;
}
textBox10.Text = processor;
textBox11.Text = Convert.ToString(n.pageSize);
textBox12.Text = Convert.ToString(n.minimumApplicationAddress);
textBox13.Text = Convert.ToString(n.maximumApplicationAddress);
textBox14.Text = Convert.ToString(n.activeProcessorMask);
textBox15.Text = Convert.ToString(n.numberOfProcessors);
textBox16.Text = Convert.ToString(n.processorType);
textBox17.Text = Convert.ToString(n.processorLevel);
textBox18.Text = Convert.ToString(n.processorRevision);
int k = 13;
for (int i = 9, j = 10; i > 0 && j < 19; i--, j++)
{
if (this.Controls["textBox" + i.ToString()].Text == this.Controls["textBox" + j.ToString()].Text)
{
this.Controls["label" + k.ToString()].Visible = true;
this.Controls["label" + k.ToString()].Text = "VS";
this.Controls["label" + k.ToString()].ForeColor = Color.DarkGreen;
}
else
{
this.Controls["label" + k.ToString()].Visible = true;
this.Controls["label" + k.ToString()].Text = "X";
this.Controls["label" + k.ToString()].ForeColor = Color.Red;
}
k++;
}
Check();
}
private void textBox8_TextChanged(object sender, EventArgs e)
{
if (textBox8.Text == textBox11.Text)
{
label14.Text = "VS";
label14.ForeColor = Color.DarkGreen;
}
else
{
label14.Text = "X";
label14.ForeColor = Color.Red;
}
Check();
}
这是我的检查功能
public void Check()
{
if (label13.Text == "VS" && label14.Text == "VS" && label15.Text == "VS" && label16.Text == "VS" && label17.Text == "VS" && label18.Text == "VS" && label19.Text == "VS" && label20.Text == "VS" && label21.Text == "VS")
{
label3.Text = "matches";
label3.ForeColor = Color.DarkGreen;
label3.Visible = true;
}
else
{
label3.Text = "inconsistencies";
label3.ForeColor = Color.Red;
label3.Visible = true;
}
}
上面的代码工作得很好,但我只是一个新手,所以我有点想尝试只使用标签,我把我的代码改成了这个
private void button1_Click(object sender, EventArgs e)
{
System.OperatingSystem OS = System.Environment.OSVersion;
GetSystemInfo(ref n);
string processor;
switch (n.processorArchitecture)
{
case 0: processor = "Intel(x84)";
break;
case 9: processor = "AMD or Intel (x64)";
break;
default: processor = "Unknown";
break;
}
label10.Text = processor;
label11.Text = Convert.ToString(n.pageSize);
label12.Text = Convert.ToString(n.minimumApplicationAddress);
label13.Text = Convert.ToString(n.maximumApplicationAddress);
label14.Text = Convert.ToString(n.activeProcessorMask);
label15.Text = Convert.ToString(n.numberOfProcessors);
label16.Text = Convert.ToString(n.processorType);
label17.Text = Convert.ToString(n.processorLevel);
label27.Text = Convert.ToString(n.processorRevision);
int k = 13;
for (int i = 9, j = 10; i > 0 && j < 19; i--, j++)
{
if (this.Controls["label" + i.ToString()].Text == this.Controls["label" + j.ToString()].Text)
{
this.Controls["label" + k.ToString()].Visible = true;
this.Controls["label" + k.ToString()].Text = "VS";
this.Controls["label" + k.ToString()].ForeColor = Color.DarkGreen;
}
else
{
this.Controls["label" + k.ToString()].Visible = true;
this.Controls["label" + k.ToString()].Text = "X";
this.Controls["label" + k.ToString()].ForeColor = Color.Red;
}
k++;
}
Check();
}
private void label11_TextChanged(object sender, EventArgs e)
{
if (label11.Text == label29.Text)
{
label19.Text = "VS";
label19.ForeColor = Color.DarkGreen;
}
else
{
label19.Text = "X";
label19.ForeColor = Color.Red;
}
Check();
}
这正在运行,但结果不正确,计算机的参数没有显示在表格上?提前谢谢