简体   繁体   English

将列表结果转换为textbox.Text属性

[英]Converting list result into textbox.Text property

I am making a little word guessing game, and I'd like for the user to be able to guess the words. 我正在做一个猜词游戏,我希望用户能够猜词。 I have the following code, and it loads words from a text file located at string filename into a list box. 我有以下代码,它将来自位于string filename的文本文件中的单词加载到列表框中。 However, I would like for the words to appear one by one in a textbox. 但是,我希望这些单词在文本框中一一出现。 The catch does not throw any errors out at all, the textbox is simply empty. catch根本不会抛出任何错误,文本框只是空的。 Is this possible and could you show me some code so I can have a play please? 这可能吗,您能给我看一些代码,以便让我玩吗? Cheers! 干杯!

I can then hide this word using one textbox, and trigger some code to move onto the next word if the typed word into the second, visible textbox is correct. 然后,我可以使用一个文本框隐藏该单词,如果在第二个可见的文本框中键入的单词正确,则触发一些代码以移至下一个单词。

async private void LoadWords(string filename)
{
    var wordList = new List<String>();
    Windows.Storage.StorageFolder localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

    try
    {

        Windows.Storage.StorageFile sampleFile = await localFolder.GetFileAsync(filename);
        var words = await Windows.Storage.FileIO.ReadLinesAsync(sampleFile);

        foreach (var word in words)
        {
            wordList.Add(word); 
        } 

        HiddenWordBox.Text = string.Join(Environment.NewLine, wordList);
        }

        catch (Exception e)
        {
            MessageDialog CatchMsg = new MessageDialog(e.Message);
        }

    }

Forgive me for my stupid question but isn't the following code required for it to be seen? 请原谅我的愚蠢问题,但是查看下面的代码不是必需的吗?

await CatchMsg.ShowAsync();

Not necessarily with the await operator. 不一定与await运算符一起使用。

Change 更改

HiddenWordBox.Text = string.Join(Environment.NewLine, wordList);

To

HiddenWordBox.Text = string.Join(Environment.NewLine, wordList.ToArray());

and the output should be as follows: http://ideone.com/DmFI0Z 并且输出应如下所示: http : //ideone.com/DmFI0Z

(There's no constructor for string.Join involving List) (没有用于string的构造函数。涉及List的联接)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM