循环问题 [英] problem with the loop while

查看:82
本文介绍了循环问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i有这个功能似乎无法正常工作,

i想要在我点击一个按钮时改变颜色,

i第一次点击,颜色必须保持粉红色,直到我点击另一次,所以它会变为黑色。



但是在第一次点击程序后完全停止响应,我再也不能点击了。



  int  on =  0 ; 
private void start_Click( object sender,EventArgs e)
{
if (on == 0
on = 1 ;
else
on = 0 ;
// MessageBox.Show(on.ToString());
< span class =code-keyword> while (on == 1
{
ind1.FillColor = System.Drawing .Color.Pink;
}
ind1.FillColor = System.Drawing.Color.Black;
// colour_adjustement(10.175.22.234);
}



谢谢你的帮助

解决方案

 while(on == 1)
{
ind1.FillColor = System.Drawing.Color.Pink;
}



这是一个非常糟糕的主意。

你已经把自己置于一个无限循环中,因此整个程序挂起。



我想你想使用 if 条件而不是 while loop。


你不需要在这里使用while循环。



< pre lang =c#> int on = 0 ;

private void start_Click(对象 sender,EventArgs e)
{
if (on == 0
{
on = 1 ;
ind1.FillColor = System.Drawing.Color.Black;
}
其他
{
on = 0 ;
// MessageBox.Show(on.ToString());
ind1 .FillColor = System.Drawing.Color.Pink;
}
}





为什么要在这里使用while循环?


你得到一个无限循环。



 (on ==  1 
{
ind1.FillColor = System.Drawing.Color.Pink;
// 你的程序在这里循环。
}





您的代码非常难看,试试这个:

  bool  on =  false ; 

private void start_Click(对象发​​件人,EventArgs e)
{
on =!on;
ind1.FillColor =
(on?System.Drawing.Color.Pink:System.Drawing.Color.Black);
// colour_adjustement(10.175.22.234);
}





祝你好运。


hi,
i have this function that doesnt seem to work right,
i want to make a shape change the colour when i click on a button,
i click the first time ,the colour has to stay pink until i click another time so it will change to black.

but after the first click the program stop responding at all,and i can''t click any more.

int on=0;
private void start_Click(object sender, EventArgs e)
        {
            if (on == 0)
                on = 1;
            else
                on = 0;
            //MessageBox.Show(on.ToString());
            while (on==1)
            {
                ind1.FillColor = System.Drawing.Color.Pink;
            }
            ind1.FillColor = System.Drawing.Color.Black;
            //colour_adjustement("10.175.22.234");
        }


thank you for your help

解决方案

while (on==1)
{
     ind1.FillColor = System.Drawing.Color.Pink;
}


This is a very bad idea.
You have put yourself into an infinite loop and thus the entire program hangs.

I guess you want to use an if condition instead of a while loop.


You don''t need a while loop here.

int on=0;

private void start_Click(object sender, EventArgs e)
{
   if (on == 0)
   {
      on = 1;
      ind1.FillColor = System.Drawing.Color.Black;
   }
   else
   {
      on = 0;
      //MessageBox.Show(on.ToString());
      ind1.FillColor = System.Drawing.Color.Pink;
   }
}



Why do you want to use a while loop here ?


You''re getting an infinite loop.

while (on==1)
{
        ind1.FillColor = System.Drawing.Color.Pink;
        //your program stays in a loop here.
}



Your code is very ugly, try this:

bool on=false;

private void start_Click(object sender, EventArgs e)
{
            on = !on;
            ind1.FillColor = 
                 (on ? System.Drawing.Color.Pink : System.Drawing.Color.Black);
            //colour_adjustement("10.175.22.234");
}



Good luck.


这篇关于循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆