private void button1_Click(object sender, EventArgs e) { // Please refer to c# naming conventions for variables. We use camelCase. string path_write = @"C:\Users\Marlena\Documents\Visual Studio 2012\Projects\Login\write.txt"; string path_read = @"C:\Users\Marlena\Documents\Visual Studio 2012\Projects\Login\read.txt"; //read_only bool check = true; //wylosowany kolor ENG _color_eng = Enum.GetName(typeof(Color_Eng), rnd); _color_write = textBox3.Text; //textbox names -------------Please add more descriptive name for textbox3 if (_color_eng == _color_write) //camelCase for variables { // MessageBox.Show("Correct"); ----- While testing implementation are you debugging? https://docs.microsoft.com/pl-pl/visualstudio/get-started/csharp/tutorial-debugger?view=vs-2019 tekst form2 = new tekst(_color_write); //naming. Use for example ShowTextForm showTextForm = new ShowTextForm(colorWhite) //form2._back_color = _color_write; / form2.Activate(); form2.Show(); List <string> Name = new List <string>(); //please use lowercase first letter for local variables List <string> Password = new List <string>(); using (var sr = new System.IO.StreamReader(path_write)) //System.IO is not needed you can add it to usings https://docs.microsoft.com/pl-pl/dotnet/api/system.io.file?view=netframework-4.8 { while (sr.Peek() >= 0) { Name.Add(sr.ReadLine()); } } System.IO.StreamWriter file1 = new System.IO.StreamWriter(path_read, true); System.IO.StreamWriter file2 = new System.IO.StreamWriter(path_write, true); _name = textBox1.Text; _login = textBox2.Text; foreach (var item in Name) { if (item == _name) { MessageBox.Show("Login exist try another one"); check = false; break; } } if (check) { Name.Add(textBox1.Text); Password.Add(textBox2.Text); file1.WriteLine(_login); file2.WriteLine(_name); } file1.Close(); file2.Close(); } else { MessageBox.Show("Wrong Name!"); } button4_Click(sender, e); //change after login }
private void button1_Click(object sender, EventArgs e) { string path_write = @"C:\Users\Marlena\Documents\Visual Studio 2012\Projects\Login\write.txt"; string path_read = @"C:\Users\Marlena\Documents\Visual Studio 2012\Projects\Login\read.txt"; //read_only bool check = true; //wylosowany kolor ENG _color_eng = Enum.GetName(typeof(Color_Eng), rnd); _color_write = textBox3.Text; if (_color_eng == _color_write) { // MessageBox.Show("Correct"); tekst form2 = new tekst(_color_write); //form2._back_color = _color_write; form2.Activate(); form2.Show(); List <string> Name = new List <string>(); List <string> Password = new List <string>(); using (var sr = new System.IO.StreamReader(path_write)) { while (sr.Peek() >= 0) { Name.Add(sr.ReadLine()); } } System.IO.StreamWriter file1 = new System.IO.StreamWriter(path_read, true); System.IO.StreamWriter file2 = new System.IO.StreamWriter(path_write, true); _name = textBox1.Text; _login = textBox2.Text; foreach (var item in Name) { if (item == _name) { MessageBox.Show("Login exist try another one"); check = false; break; } } if (check) { Name.Add(textBox1.Text); Password.Add(textBox2.Text); file1.WriteLine(_login); file2.WriteLine(_name); } file1.Close(); file2.Close(); } else { MessageBox.Show("Wrong Name!"); } button4_Click(sender, e); //change after login }