所以我的程序运行良好,但每当我注册表单2它说它找不到路径我不知道什么是错的请帮助我稍后需要通过它,我不知道我是否需要做一个新的文件夹在C:刚拿到LOGIN.IDC#帮助无法找到路径(登录系统)
{ 公共部分Form1类:表格{ 公共 字符串的用户名,密码; public Form1() { InitializeComponent(); }
private void button2_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
var sr = new System.IO.StreamReader("C\\" + textBox1.Text + "\\login.ID");
username = sr.ReadLine();
password = sr.ReadLine();
sr.Close();
if (username == textBox1.Text && password == textBox2.Text)
MessageBox.Show("Log-in Successfull", "Success!");
else
MessageBox.Show("Username or password is wrong! ","Error!");
}
catch (System.IO.DirectoryNotFoundException)
{
MessageBox.Show("The user doesn't exist!", "Error!");
}
}
}
}
//形式2
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
var sw = new System.IO.StreamWriter ("C\\" + textBox1.Text + "\\login.ID");
sw.Write(textBox1.Text + "\n" + textBox2.Text);
sw.Close();
}
catch(System.IO.DriveNotFoundException)
{
System.IO.Directory.CreateDirectory("C:\\" + textBox1.Text);
var sw = new System.IO.StreamWriter("C\\" + textBox1.Text + "\\login.ID");
sw.Write(textBox1.Text + "\n" + textBox2.Text);
sw.Close();
}
}
}
}
您继续混合“C \\”和“C:\\”。什么是“C \\”?这是无稽之谈。修复你的路径,使它们始终如一“C:\\”。 – itsme86
我该如何解决它?我应该为C创建一个文件夹:\\ 示例C \ test \ –
示例:@form 1 var sr = new System.IO.StreamReader(“C \ test1 \”+ textBox1.Text +“\\ login.ID “); username = sr.ReadLine(); password = sr.ReadLine(); sr.Close(); –