我有一个程序可以在我的计算机上获取系统信息,我想让它比较另一台计算机上的信息系统,如果参数相同,那么我写一条消息“匹配”,如果它们不是我的不一致,当我使用下面的文本框时,我的程序工作得很好
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();
}
这是运行但是结果不正确并且计算机上的参数没有显示在表单上?提前感谢
答案 0 :(得分:0)
最有可能是以下功能:
private void label11_TextChanged(object sender, EventArgs e)
未绑定Label
且标识为label11
。
要确保绑定,请在表单的Load
事件中编写以下代码:
label11.OnTextChanged +=label11_TextChanged;