C#的有关”(是否缺少 using 指令或程序集引用?)的问题。
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.StreamWriter;
namespace _4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 统计ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("共有" + listView1.Items.Count + "条记录", "信息提示", MessageBoxButtons.OK);
}
private void 写入ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty & textBox2.Text == string.Empty & textBox3.Text == string.Empty)
{
MessageBox.Show("要写入的文件内容不能为空");
}
else
{
SaveFileDialog of = new SaveFileDialog();
of.Filter = "二进制文件(*.dat)|*.dat";
if (of.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(of.FileName, true);
sw.WriteLine(textBox1.Text);
sw.WriteLine(textBox2.Text);
sw.WriteLine(textBox3.Text);
sw.Close();
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
}
}
}
private void 读取ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog1.Filter = "二进制文件(*.dat)|*.dat";
if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
StreamReader sr = new StreamReader(of.FileName);
StreamReader st = new StreamReader(of.FileName);
StreamReader sd = new StreamReader(of.FileName);
textBox1.Text = sr.ReadToEnd();
textBox2.Text = st.ReadToEnd();
textBox3.Text = sd.ReadToEnd();
sr.Close();
st.Close();
sd.Close();
}
}
}
}
因为全部太长了 只截取有问题的部分 希望大虾们能看懂 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.StreamWriter;
namespace _4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 统计ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("共有" + listView1.Items.Count + "条记录", "信息提示", MessageBoxButtons.OK);
}
private void 写入ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty & textBox2.Text == string.Empty & textBox3.Text == string.Empty)
{
MessageBox.Show("要写入的文件内容不能为空");
}
else
{
SaveFileDialog of = new SaveFileDialog();
of.Filter = "二进制文件(*.dat)|*.dat";
if (of.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(of.FileName, true);
sw.WriteLine(textBox1.Text);
sw.WriteLine(textBox2.Text);
sw.WriteLine(textBox3.Text);
sw.Close();
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
}
}
}
private void 读取ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog1.Filter = "二进制文件(*.dat)|*.dat";
if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
StreamReader sr = new StreamReader(of.FileName);
StreamReader st = new StreamReader(of.FileName);
StreamReader sd = new StreamReader(of.FileName);
textBox1.Text = sr.ReadToEnd();
textBox2.Text = st.ReadToEnd();
textBox3.Text = sd.ReadToEnd();
sr.Close();
st.Close();
sd.Close();
}
}
}
}
因为全部太长了 只截取有问题的部分 希望大虾们能看懂 展开
3个回答
展开全部
..............
using System.Text;
using System.Windows.Forms;
using System.IO; //是System.IO不是System.StreamWriter
namespace _4
{
public partial class Form1 : Form
...............
using System.Text;
using System.Windows.Forms;
using System.IO; //是System.IO不是System.StreamWriter
namespace _4
{
public partial class Form1 : Form
...............
更多追问追答
追问
修改为IO之后,还有错误
错误 1 当前上下文中不存在名称“OpenFileDialog1”
错误 3 当前上下文中不存在名称“of”
追答
你不是没有学过C#吧,从工具箱里拖个OpenFileDialog和SaveFileDialog并改下名字就可以了啊...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
其实只把出错的提示贴出来就行,“是否缺少 using 指令或程序集引用”前面说的是啥,是啥缺少using指令
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System.IO;
追问
修改为IO之后,还有错误
错误 1 当前上下文中不存在名称“OpenFileDialog1”
错误 3 当前上下文中不存在名称“of”
追答
添加OpenFileDialog控件
private void 读取ToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "二进制文件(*.dat)|*.dat";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{ textBox1.Text = string.Empty; textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
StreamReader sr = new StreamReader(openFileDialog1.FileName);
StreamReader st = new StreamReader(openFileDialog1.FileName);
StreamReader sd = new StreamReader(openFileDialog1.FileName);
textBox1.Text = sr.ReadToEnd(); textBox2.Text = st.ReadToEnd();
textBox3.Text = sd.ReadToEnd(); sr.Close(); st.Close(); sd.Close();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询