I am trying to figure out how to read multiple lines whith StreamReader. I have a text file with a list of commands inside it that I need to read from. My code works, however it will only read the first line. This causes me to have to move all my commands to a single line with a space between them. This is not a very tidy way of doing this seeing as I need to leave comments next to the commands. Example: CONNECT: "Connects to given IP."
public void ConsoleEnter_KeyDown(object sender, KeyEventArgs e) { string line; if (e.KeyCode == Keys.Enter) { // Read the file and display it line by line. StreamReader file = new StreamReader("C:\\Users\\Home\\Desktop\\commands.txt"); while ((line = file.ReadLine()) != null) { if (line.Contains(ConsoleEnter.Text)) { COMBOX.Items.Add(ConsoleEnter.Text); COMBOX.Items.Remove(""); ConsoleEnter.Text = ""; } else { COMBOX.Items.Add("Invalid Command"); COMBOX.Items.Remove(""); ConsoleEnter.Text = ""; } } } }