且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么文字不会改变第二次

更新时间:2023-12-06 08:33:46

您可能希望逐行浏览代码并考虑您的逻辑。您可能还想查看两个if语句并查看您将按钮的文本设置为是什么。



BTW:您只需要一个if语句,不是2.


[不是答案,应该删除。此外,这篇文章没有任何意义-SA]



而不是如果条件我只需要使用if else


Quote:

if(button1.Text ==button1)

{

button1 .Text =button2;

}

if(button1.Text ==button2)

{

button1.Text =button2; //< - 错误的行

}





以粗体显示的错误行,将其更改为

 button1.Text =button1; 


if (button1.Text == "button1")
           {
               button1.Text = "button2";
           }
           if (button1.Text == "button2")
           {
               button1.Text = "button1";
           }




why its not working

You might want to step through the code line-by-line and think about your logic. You might also want to look at both if statements and see what you''re setting the Text of the button to.

BTW: You only need ONE if statement, not 2.


[Not an answer, should be removed. Besides, this post makes no sense —SA]

instead of to if conditions i just needed to use if else


Quote:

if (button1.Text == "button1")
{
button1.Text = "button2";
}
if (button1.Text == "button2")
{
button1.Text = "button2"; // <-- wrong line
}



Wrong line in bold, change it to

button1.Text = "button1";