0

コードの音声合成クラスが 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;
        }         
    }

}       

}

4

1 に答える 1

2

何を達成したいのかよくわかりませんが、コードの一部が必要だと思います

foreach(var item in testLstSet.lstWordlist.Items)
        {
            speech.SpeakAsync(item.ToString());
        }

呼び出すとtestLstSet.lstWordlist.Items.ToString();、アイテムのタイプ、つまり が取得されますobject.collections。このコレクションの要素を取得する場合は、次のようにインデクサーを使用する必要があります。testLstSet.lstWordlist.Items[0].ToString();

于 2013-07-06T22:00:14.737 に答える