Hi
I'm very new to programming and I'm learning C# for the first time with no experience.
I just finished designing a program which counts the vowels in a sentence.
Now I would like to count the vowels while typing it to the text box. I'm wondering what event/events is/are being used.
I'm not quite sure if it's something to do with "KeyPress" or "KeyUp".
I would appreciate your help. Thanks.
Here is my code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCount_Click(object sender, EventArgs e)
{
string yourSentence;
yourSentence = textBox1.Text.ToLower().Trim();
int counta = 0;
int counte = 0;
int counti = 0;
int counto = 0;
int countu = 0;
int j = counta + counte + counti + counto + countu;
foreach (char v in yourSentence)
{
switch (v)
{
case 'a':
counta++;
j++;
break;
case 'e':
counte++;
j++;
break;
case 'i':
counti++;
j++;
break;
case 'o':
counto++;
j++;
break;
case 'u':
countu++;
j++;
break;
}
}
listBox1.Items.Add("There are " + counta.ToString().Trim() + " a's in the sentence");
listBox1.Items.Add("There are " + counte.ToString().Trim() + " e's in the sentence");
listBox1.Items.Add("There are " + counti.ToString().Trim() + " i's in the sentence");
listBox1.Items.Add("There are " + counto.ToString().Trim() + " o's in the sentence");
listBox1.Items.Add("There are " + countu.ToString().Trim() + " u's in the sentence");
listBox1.Font = new Font("Arial", 11, FontStyle.Bold);
listBox1.ForeColor = Color.DarkViolet;
listBox1.Items.Add("All in all there are " + j.ToString().Trim() + " vowels in the sentence");
listBox1.ForeColor = Color.DeepSkyBlue;
}
private void btnClear_Click(object sender, EventArgs e)
{
textBox1.Text = null;
listBox1.Items.Clear();
}