在 for 循环中使用转义键退出 [英] exit with escape key in for loop
本文介绍了在 for 循环中使用转义键退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个循环并且正在工作:
I have this loop and is working :
for (int x = 0; x < nombres.Length; x++)
{
ValidXX.Text = x.ToString(); ValidXY.Text = nombres.Length.ToString();
origen = nombres[x];
cambia = nombres[x];
pedrito = control.ValidarDocumentoXML(cambia);
if (pedrito == true)
{ }
else
/* File.Move (origen , destino );*/
try
{ }
catch(IOException iox)
{ MessageBox.Show(iox.Message); }
{ /* corrupto[x] = cambia; */ MessageBox.Show("malo" + cambia); }
}
我想用转义键打破这个循环,我试过这个:
I want o break this loop with the escape key , i have try with this :
private void Importar2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape) { }
}
但我不能将此 key_down 写入 for 循环.
but i can not write this key_down into the for loop.
推荐答案
你可以这样做:
bool escPressed = false;
....
//run your loop in a different thread
Thread thread = new Thread(new ThreadStart(MyLoop));
thread.Start();
....
void MyLoop()
{
for (int x = 0; x < nombres.Length; x++)
{
if(escPressed) break;
ValidXX.Text = x.ToString(); ValidXY.Text = nombres.Length.ToString();
origen = nombres[x];
cambia = nombres[x];
pedrito = control.ValidarDocumentoXML(cambia);
if (pedrito == true)
{ }
else
/* File.Move (origen , destino );*/
try
{ }
catch(IOException iox)
{ MessageBox.Show(iox.Message); }
{ /* corrupto[x] = cambia; */ MessageBox.Show("malo" + cambia); }
}
}
private void Importar2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape) { escPressed = true;}
}
这篇关于在 for 循环中使用转义键退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文