T 我在尝试让我的代码的语音合成类从 ListBoxItem.toString() 中背诵单词时遇到了很多麻烦。btnStart_Clicked() 方法中的 foreach 循环是我认为问题开始的地方:
test = testLstSet.lstWordlist.Items.ToString();
speech.SpeakAsync(test);
语音合成器告诉我:
“system.windows.forms.listbox + object.collections”
有人可以帮忙吗?对不起所有的代码,但我想给你尽可能多的信息。
我究竟做错了什么?
public partial class MyClass : Form
{
private bool testStarted = false;
private SpeechSynthesizer speech;
private string evalWord = null;
string test;
bool testBit = false;
TestList testLstSet;
public SpellingBee(TestList tstLst)
{
InitializeComponent();
testLstSet = tstLst;
speech = new SpeechSynthesizer();
speech.SpeakAsync("Hello! Welcome to The test. Shall we begin?");
}
private void btnStart_Click(object sender, EventArgs e)
{
if (testStarted)
return;
else
{
testStarted = true;
foreach(var item in wrdLstSet.lstWordlist.Items)
{
test = testLstSet.lstWordlist.Items.ToString();
speech.SpeakAsync(test);
while(!testBit)
{
}
}
}
}
private void btnSubmit_Click(object sender, EventArgs e)
{
string evalWord = this.txtAnswer.Text;
bool answer = string.Equals(evalWord, test, StringComparison.OrdinalIgnoreCase);
if (answer)
{
speech.SpeakAsync("That's right! Good Job!");
testbit = true;
}
else
{
speech.SpeakAsync("That is incorrect.");
testbit = true;
}
}
}
}