我想知道当您在文本框中键入句子时,在计算元音时使用了哪些事件/事件。
我不太确定这是否与“ KeyPress
”或“ KeyUp
”有关。
我会很感激你的帮助。
=====
这就是我现在卡住的地方:
private void btnCount_Click(object sender, EventArgs e)
{
string yourSentence;
yourSentence = textBox1.Text.ToLower().Trim();
char ch1 = 'a';
char ch2 = 'e';
char ch3 = 'i';
char ch4 = 'o';
char ch5 = 'u';
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)
{
if (v == ch1) { counta++; j++; }
else if (v == ch2) { counte++; j++; }
else if (v == ch3) { counti++; j++; }
else if (v == ch4) { counto++; j++; }
else if (v == ch5) { countu++; j++; }
}
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.Items.Add("All in all there are " + j.ToString().Trim() + " vowels in the sentence");
private void textBox1_KeyDown(object sender, EventArgs e)
{
string yourSentence;
yourSentence = textBox1.Text.ToLower().Trim();
//I think I have to add the codings here. But what will happened to the
//btnCount_Click?
}