hi there. so i'm new to c# and am trying to make a simple "counter" in a windows forums application.
i've created a text box (for input) and a rich text box (for output).
if i press the "1" key in the rich text box i'd like the rich text box to increment it's output.
private void textBox1_TextChanged(object sender, EventArgs e)
{
int one=0;
//while (one<10)
if (textBox1.Text == "1")
{
one = one + 1;
richTextBox1.Text = " " + one;
}
textBox1.Text = "";
}
the problem is if i enable the while loop , the program hangs :( how to i get keep incrementing?
i am c# express on vista. also is there a difference between a windows form application and a windows application?
i'd appreciate any help.
EDIT:
nevermind i figured out the prob. was having trouble with a global variable. heres a working version if anyone wants it.
public partial class Form1 : Form
{
int one = 0;
public Form1()
{
InitializeComponent();
this.textBox1.Focus();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "1")
{
one = one + 1;
richTextBox1.Text = " " + one;
}
textBox1.Text = "";
}
}
Loading
Guest UserPosted Jan 14, 2009, 2:54 PM
System.Threading.Thread.Sleep(100);
Sleep(100) tells your program to stop what it's doing for 100ms so that Windows can handle other processes while your loop is executing. Otherwise the other apps & processes running will slow down dramatically.
You can adjust the 100 to whatever time interval fits your situation best.
Ryan AlfordPosted Jan 14, 2009, 10:49 AM