循环问题 [英] problem with the loop while
问题描述
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 anif
condition instead of awhile
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屋!