0

I am using a for loop to keep adding items to an array by keep pressing the button, i call it btnEnter, after input some data. something like

            double[] inputarr = new double[10];
            for (int i = 0; i < inputarr.Length; i++)
            {
                inputarr[i] = Double.Parse(txtAmount.Text);

            }

I want to jump out from the loop and perform something by clicking another button. Can button_click() do the job for me? like

            for (int i = 0; i < inputarr.Length; i++)
            {
                inputarr[i] = Double.Parse(txtAmount.Text);
                if (btnStop_Click() == true)
                {
                    break;
                }
            } 

how to make this work? can anyone help me with this?

Yi Xu Chee
  • 67
  • 1
  • 1
  • 13
  • You shouldn't need to go to the UI for automation logic. If you need to automatically "click a button" from within code, then what you _actually_ need is to extract the business logic from the button's click handler into a common method and automatically call that method. – David Apr 22 '12 at 15:03

2 Answers2

0

If I understand you correctly, you want to prompt for input 10 times in a row. You're thought process is a bit inverted. I think all you need is a prompt dialog. See Prompt Dialog in Windows Forms for an example.

Community
  • 1
  • 1
Rake36
  • 992
  • 2
  • 10
  • 17
0

You can call another button like this

for (int i = 0; i < inputarr.Length; i++)
        {
            inputarr[i] = Double.Parse(txtAmount.Text);
            btnStop_Click(null,null);
                break;
            }
        }  

or u can use timer

  int i = 0;Timer t = new Timer();
 button_click(object sender,event e)
  {

        t.Interval = 4000;
        t.Tick += t_Tick;
        t.Start();
  }
  void t_Tick(object sender, EventArgs e)
    {
        if (i <= 9) { inputarr[i] = Double.Parse(txtAmount.Text); }

        else { t.Stop(); Do other staff  }
        i++;
    }
Moayad Myro
  • 294
  • 1
  • 3
  • 12