2
Answers

new to c#, how to create a windows forms application "recur"

mike henderson

mike henderson

15y
3.6k
1
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 = "";
    
        }
    }
Answers (2)