c# – 列表框中的StreamReader和Writer
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 列表框中的StreamReader和Writer,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2069字,纯文字阅读大概需要3分钟。
内容图文
![c# – 列表框中的StreamReader和Writer](/upload/InfoBanner/zyjiaocheng/796/0188b5d932424f0da5a8783d416104f0.jpg)
问题1:无论用户在列表框中显示的文本框中输入什么,但是其他文本首先显示,然后用户输入的内容最后显示.
问题2:我的StreamReader / StreamWriter我不断收到新的C#1601错误代码所以我不知道所有条款.
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
解决方法:
我真的不明白你的第一个问题,其他文字首先出现了什么?
对于你的第二个问题,我认为你有其他问题.首先你使用的是:
if (loadButton.ShowDialog() == DialogResult.OK)
和
if (saveOrder.ShowDialog() == DialogResult.OK)
据我所知,这些是你点击的按钮,它们没有ShowDialog方法.
您实际看到的错误是由于您尝试从我仍然怀疑的按钮获取FileName属性(并由错误消息备份 – ‘Button’不包含’FileName’的定义):
loadButton.FileName
和
saveOrder.FileName
我怀疑你实际应该使用的是OpenFileDialog和SaveFileDialog控件,但实际上你已经引用了你点击的按钮.
内容总结
以上是互联网集市为您收集整理的c# – 列表框中的StreamReader和Writer全部内容,希望文章能够帮你解决c# – 列表框中的StreamReader和Writer所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。