等待窗体鼠标单击
本文关键字:单击 鼠标 窗体 等待 | 更新日期: 2023-09-27 18:25:42
我有一个while循环,每次循环结束时,我都会打印一个mesagebox来显示结果。单击"ok"按钮后,循环将继续。我想要的是将我的结果打印到主窗体中的文本框中,当在主窗体中捕捉到鼠标单击时,循环将继续。知道吗?
代码:
private void button1_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(File.OpenRead(path)); //read file
string line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
string iw = encode.I_type(line); //doWork
textBox1.Text = (iw);
label6.Text = (iw.Length).ToString();
string strHex = encode.add_digits(Convert.ToInt32(iw, 2).ToString("X"), 8);
textBox2.Text = strHex;
MessageBox.Show(line); // when hit ok, goes at the begining of the while loop
}
更改代码以匹配您的模式:
private StreamReader sr;
private void button1_Click(object sender, EventArgs e)
{
sr = new StreamReader(File.OpenRead(path)); //read file
ProcessOneLine();
}
private void buttonNext_Click(object sender, EventArgs e)
{
ProcessOneLine();
}
private void ProcessOneLine()
{
if ( sr == null )
return;
string line = string.Empty;
line = sr.ReadLine()
if ( line == null )
{
sr = null;
return;
}
string iw = encode.I_type(line); //doWork
textBox1.Text = (iw);
label6.Text = (iw.Length).ToString();
string strHex = encode.add_digits(Convert.ToInt32(iw, 2).ToString("X"), 8);
textBox2.Text = strHex;
}