在我的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);
}
}
加载表单时不会发生任何事情。如果我添加第一行,那么它实际上发生了。就像如果我把一个消息框作为这个事件的第一行,它就会发生。但这段代码中没有任何内容。
更改
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");
您忘记了冒号