C# winform如何实现这个功能?

if (comboBox1.Text == "TCP Server")
{
this.button1.Text = "连接";
textBox1.Enabled = true;
textBox2.Enabled = true;
comboBox1.Enabled = true;
}
else
{
switch (this.button1.Text)
{
case "断开":
this.button1.Text = "连接";
textBox1.Enabled = true;
textBox2.Enabled = true;
comboBox1.Enabled = true;
break;
case "连接":
this.button1.Text = "断开";
textBox1.Enabled = false;
textBox2.Enabled = false;
comboBox1.Enabled = false;
break;
default:
break;
}
}
代码基本我写完了,但是if里面我写的不对,我希望点击TCP Server 时候swtich不要循环了,就是没有任何变化?

第1个回答  2014-08-06
if (comboBox1.Text.trim() == "TCP Server")//去一下空格试试
第2个回答  2014-08-06

按你的代码

if (comboBox1.Text == "TCP Server")
{
this.button1.Text = "连接";
                textBox1.Enabled = true;
                textBox2.Enabled = true;
                comboBox1.Enabled = true;
}
不会进到switch里边啊?有什么问题···

追问

不过我在调试软件时候if语句没用还是进入switch,不知道为什么?

追答

这不科学,你在if (comboBox1.Text == "TCP Server")这一句的位置下个断点,看看comboBox1.Text到底是什么?

追问

问题已经解决了,谢谢。

本回答被提问者采纳
相似回答