how to perform a keypress event untill a button is clicked in the form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • giri87
    New Member
    • May 2009
    • 4

    how to perform a keypress event untill a button is clicked in the form

    hi !!!i m trying to perform a key press event untill a button is clicked .How can i keep a key press event in a loop untill a button is clicked?? please help !!!
    here is a part of the code, tryin to explain what i m tryin to do---->


    private void textBox1_KeyPre ss(object sender, KeyPressEventAr gs e)
    {
    int i = 0;

    while(untill button not clicked)
    {
    if (e.KeyChar == 13)
    {
    string c = textBox1.Lines[i];
    i++;
    }
    }
    }
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Create a boolean variable to represent whether a button has been clicked or not. Before the while loop, initialize it.

    On the button OnClick listener, set this variable. The thread running the loop should break out of the while loop.

    Comment

    Working...