Question 1: whatever the user enters in the text box displays in the listbox but other text is showing up first then what the user enters shows up at the end.
Question 2: my StreamReader
/ StreamWriter
I keep getting 1601 error code to new to C# so I don't know all the terms.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace foodOrderApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//textDialog = new SaveFileDialog();
//textDialog.Filter = ""
}
private void addToListButton_Click(object sender, EventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(foodText.Text, "^[a-zA-Z]"))
{
MessageBox.Show("This textbox only accepts alphebetical characters");
}
else
{
displayFoodOrder.Items.Add(foodText.ToString());
}
}
private void loadButton_Click(object sender, EventArgs e)
{
if (loadButton.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(
new FileStream(loadButton.FileName,
FileMode.Create,
FileAccess.ReadWrite)
);
sw.WriteLine(displayFoodOrder.Text);
sw.Close();
}
}
private void saveOrder_Click(object sender, EventArgs e)
{
if (saveOrder.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(
new FileStream(saveOrder.FileName,
FileMode.Open,
FileAccess.Read)
);
}//end if
}
}
}
Error:
CS1061 'Button' does not contain a definition for 'FileName' and no extension method 'FileName' accepting a first argument of type 'Button' could be found (are you missing a using directive or an assembly reference?)
line 42