0

Do you see anything concerning? Would you do something differently? Any comments?

public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
        }

        // String array
        private string[] myWords = new string[4];
        private string currentWord;
        private int wordIndex;

        private void parseWords()
        {
            myWords[0] = "The ";
            myWords[1] = "fox ";
            myWords[2] = "jumps ";
            myWords[3] = "slowly.";

            currentWord = myWords[0];
            txtWordDisplay.Text = currentWord;
            wordIndex = 1;
        }

        private bool nextWord(int wordIndexSet)
        {
            // Make sure it's not the last element
            if (wordIndexSet != myWords.Length)
            {
                int arrayIndex;
                wordIndex++;
                arrayIndex = wordIndex - 1;

                currentWord = myWords[arrayIndex];
                txtWordDisplay.Text = currentWord;
                return true;
                
            }
            else
            {
                return false;
            }   
        }

        private void button1_Click(object sender, EventArgs e)
        {
            parseWords();
            txtWordDisplay.Enabled = true;
            lblToType.Enabled = true;
            txtInput.Enabled = true;
            
        }

        private void txtInput_TextChanged(object sender, EventArgs e)
        {
            if (txtInput.Text == currentWord)
            {
                txtInput.Text = "";

                if (nextWord(wordIndex))
                {
                    // Carry on typing...
                }
                else
                {
                    txtInput.Enabled = false;
                    MessageBox.Show("Finished!");
                    
                }
            }

        }
    }

Basically, the program loads, you click the start button, it enables the textbox for you to type in, it shows you a word to type and you type it, if it matches it empties the text box and you start with the next word until it reaches the last word.

I do have one question, how do I rename button1_Click, I've renamed it directly in visual studio (via the properties window) but it hasn't updated in the codeview?

Thank you :)

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by spunkywacko
0

Hi,
it hard to tell what could be done better. There is to much to learn. This code looks ok, and it works, but I dont know exaclty what do you want to do with it.

1

Change private string[] myWords = new string[4]; on line 9 into private List<string> myWords = new List<string>();

Votes + Comments
good suggestion :)
0

To rename the event, just rename it in the code.

You will probably get an error saying something like 'button1_click() not defined'
That is because there is another file that visual studio made for you that sets all the properties for all of your controls/components.

Just double click the error and make sure you change the name of the event += line to reflect the new name of the event.

0

Hi,
it hard to tell what could be done better. There is to much to learn. This code looks ok, and it works, but I dont know exaclty what do you want to do with it.

It's a really really basic 'typing tutor'. Well in the making anyway. :)

Thank you everyone really appreciated.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.