等待表单鼠标单击

时间:2014-10-04 17:13:15

标签: c#

我有一个while循环,每次循环结束时,我打印一个mesagebox来显示结果。单击“确定”按钮时,循环继续。我想要的是将我的结果打印到主窗体中的文本框,并在主窗体中捕获鼠标时循环将继续。 任何的想法?

代码:

    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

        }

1 个答案:

答案 0 :(得分:0)

更改您的代码以符合您的模式:

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;
}