問題1:無論用戶在文本框中輸入的內容顯示在列表框中,但其他文本先顯示出來,然後用戶輸入的內容顯示在最後。列表框中的StreamReader和Writer
問題2:我的StreamReader
/StreamWriter
我不斷收到1601錯誤代碼,以新的C#,所以我不知道所有的條款。
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
}
}
}
錯誤:
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
能否請**至少**發佈完整和正確的錯誤信息 - 不僅僅是「類似1061」....和**其中**在你的代碼是否發生錯誤 - 在哪行代碼? –
錯誤\t CS1061 \t'Button'不包含'FileName'的定義,並且沒有找到接受'Button'類型的第一個參數的擴展方法'FileName'(您是否缺少using指令或程序集引用?)\t LoadButton.Filename和saveOrder.filename以及saveOrderDialog方法中的showDialog()和Load Button方法 –
請**不要**將代碼示例或示例數據放入註釋中 - 因爲您無法對其進行格式化,所以它* *非常困難**閱讀它....相反:**更新**您的問題通過編輯它提供額外的信息!謝謝。 –