[英]if statements in C# for a textbox to change back to normal when i press a button for the second time
This is the code that i used to change the text in the text box from "Livre" to "Ocupado" What code should i use to change it from "Ocupado" to "Livre"这是我用来将文本框中的文本从“Livre”更改为“Ocupado”的代码我应该使用什么代码将其从“Ocupado”更改为“Livre”
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text="Ocupado";
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Livre")
{
textBox1.Text = "Ocupado";
}
else
{
textBox1.Text = "Livre";
}
}
you can add a variable to your class您可以将变量添加到 class
eg:例如:
bool livre = true;
private void button1_Click(object sender, EventArgs e)
{
if (livre)
{
textBox1.Text="Ocupado";
}
else
{
textBox1.Text="Livre";
}
livre = !livre;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.