Form1 Load Event仅执行第一个语句

时间:2013-07-14 07:18:06

标签: c#

在我的Form1活动中,并非一切都已完成。实际上只执行了第一行。

private void Form1_Load(object sender, EventArgs e)
    {
        //Save the currentUser text document's contents into the currentUser string
        System.IO.StreamReader file = new System.IO.StreamReader("C\\Users\\WoopyCat\\AppData\\Roaming\\.minecraft\\currentUser.txt");
        currentUser = file.ReadLine();

        //Save the currentUser into the textbox
        TBcurrentUser.Text = "The current user is " + currentUser + ".";

        //Set the default text for the textbox
        TBchangeTo.Text = "Whose Minecraft folder are you switching to?";

        //Add the default two items to the listbox
        LBfiles.Items.Add("Minecraft folders:" + Environment.NewLine);
        LBfiles.Items.Add("---------------------------------------------------------------------------------------------------------------------------");

        //Create the directory if it doesn't exist
        if (!Directory.Exists("C:\\Users\\WoopyCat\\AppData\\Roaming\\" + folderName))
        {
            Directory.CreateDirectory("C:\\Users\\WoopyCat\\AppData\\Roaming\\" + folderName);
        }

        //Set the default instructions in the textbox
        TBinstructions.Text = instructions;

        //Add each directory to the listbox
        foreach (string value in Directory.GetDirectories("C:\\Users\\WoopyCat\\AppData\\Roaming\\" + folderName))
        {
            //Remove the file location from the string
            each = value.Replace("C:\\Users\\WoopyCat\\AppData\\Roaming\\.MCSwitcher\\", "");
            LBfiles.Items.Add(each + Environment.NewLine);
        }
    }

表单加载时没有任何反应。如果我添加第一行,那么它实际上会发生。就像我在此事件中将消息框称为第一行一样,它就会发生。但是这段代码中没有任何内容。

1 个答案:

答案 0 :(得分:2)

变化

System.IO.StreamReader file = new System.IO.StreamReader("C\\Users\\WoopyCat\\AppData\\Roaming\\.minecraft\\currentUser.txt");

System.IO.StreamReader file = new System.IO.StreamReader("C:\\Users\\WoopyCat\\AppData\\Roaming\\.minecraft\\currentUser.txt");

你忘记了结肠