Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: May 2009
Posts: 4
#1: May 17 '09
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_KeyPress(object sender, KeyPressEventArgs e)
{
int i = 0;

while(untill button not clicked)
{
if (e.KeyChar == 13)
{
string c = textBox1.Lines[i];
i++;
}
}
}
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#2: May 19 '09

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


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.
Reply