using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace test {
public partial class Form1 : Form { private string FileName = "a.txt"; private string FileContent;
private void btnSaveFile_Click(object sender,EventArgs e) { FileInfo info = new FileInfo(FileName); if (!info.Exists) { MessageBox.Show("File Doesn't Exist! Will Creat"); } FileStream fs = info.open(FileMode.OpenOrCreat,FileAccess.ReadWrite,FileShare.ReadWrite); StreamWriter sw = new StreamWriter(fs); sw.WriterLine(FileContent); sw.Close(); fs.Close(); } private void btnLoadFile_Click(object sender, EventArgs e) { FileInfo info = new FileInfo(FileName); if (!info.Exists) { MessageBox.Show("File Doesn't Exist ! Will Creat!"); } FileStream fs = info.Open(FileMode.OpenOreate,FileAccess.ReadWrite,FileShare.Readwrite); StreamReader sr = new StreamReader(fs); string strContent = sr.ReadLine(); sr.Close(); fs.Close(); MessageBox.Show("File Content is:"+strContent); } private void btnException_Click(object sender, EventArgs e) { throw new Exception("I throw an Exception,but i don't know what's to do ,hehe!"); } private void HelloWorld_Load(object sender, EventArgs e) { FileInfo info = new FileInfo(FileName); if (!info.Exists) { MessageBox.Show("File Does't Exist!Will Creat!"); } FileStream fs = info.Open(FileMode.OpenOrCreate,FileAccess.ReadWriter,FileShare.ReadWrite); StreamReader sr = new StreamReader(fs); string StrContent = sr.ReadLine(); sr.Close(); fs.Close(); this.txtContent.Text = StrContent; this.FileContent = StrContent; } 运行时第二个EventArgs处发生之前的错误!
我又在 namespace test {
public partial class Form1 : Form { private string FileName = "a.txt"; private string FileContent; 之后加了 public class EventArgs { public EventArgs.EventArgrs(); } 但还是不对,你帮忙看一下,谢了!
//你给的代码 using System.Text; 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;"?
还真是没有using System; 晕死,我连这都没看到……
我输入过using System; 但还是有问题的!
请不要把问题孤立来看。 输入using System还有问题是可能你别的地方有错误。 这句是必须的
public partial class Form1 : Form { public Form1()//楼主的代码没有这个???? { InitializeComponent(); } }
我试过了,有和没有 public Form1() { InitializeComponent(); } 效果是一样的
现在只有一个错误了: public class EventArgs { public EventArgs.EventArgs() ; } 在这一句中显示错误“类、结构或接口成员声明中的标记“(”无效”,怎么改啊?
把他放在和form1类平行的位置. 楼主着段代码是干什么用的?重写吗?
namespace test {
public partial class Form1 : Form { private string FileName = "a.txt"; private string FileContent; } public class EventArgs { public EventArgs.EventArgrs(); } }
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
private string FileName = "a.txt";
private string FileContent;
private void btnSaveFile_Click(object sender,EventArgs e)
{
FileInfo info = new FileInfo(FileName);
if (!info.Exists)
{
MessageBox.Show("File Doesn't Exist! Will Creat");
}
FileStream fs = info.open(FileMode.OpenOrCreat,FileAccess.ReadWrite,FileShare.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.WriterLine(FileContent);
sw.Close();
fs.Close();
} private void btnLoadFile_Click(object sender, EventArgs e)
{
FileInfo info = new FileInfo(FileName);
if (!info.Exists)
{
MessageBox.Show("File Doesn't Exist ! Will Creat!");
}
FileStream fs = info.Open(FileMode.OpenOreate,FileAccess.ReadWrite,FileShare.Readwrite);
StreamReader sr = new StreamReader(fs);
string strContent = sr.ReadLine();
sr.Close();
fs.Close();
MessageBox.Show("File Content is:"+strContent);
} private void btnException_Click(object sender, EventArgs e)
{
throw new Exception("I throw an Exception,but i don't know what's to do ,hehe!");
} private void HelloWorld_Load(object sender, EventArgs e)
{
FileInfo info = new FileInfo(FileName);
if (!info.Exists)
{
MessageBox.Show("File Does't Exist!Will Creat!");
}
FileStream fs = info.Open(FileMode.OpenOrCreate,FileAccess.ReadWriter,FileShare.ReadWrite);
StreamReader sr = new StreamReader(fs);
string StrContent = sr.ReadLine();
sr.Close();
fs.Close();
this.txtContent.Text = StrContent;
this.FileContent = StrContent;
}
运行时第二个EventArgs处发生之前的错误!
namespace test
{
public partial class Form1 : Form
{
private string FileName = "a.txt";
private string FileContent;
之后加了
public class EventArgs
{
public EventArgs.EventArgrs();
}
但还是不对,你帮忙看一下,谢了!
第二个是指
private void btnLoadFile_Click(object sender, EventArgs e) 这里么?
//你给的代码
using System.Text;
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;"?
晕死,我连这都没看到……
但还是有问题的!
输入using System还有问题是可能你别的地方有错误。
这句是必须的
public partial class Form1 : Form
{
public Form1()//楼主的代码没有这个????
{
InitializeComponent();
}
}
public Form1()
{
InitializeComponent();
}
效果是一样的
public class EventArgs
{
public EventArgs.EventArgs() ;
}
在这一句中显示错误“类、结构或接口成员声明中的标记“(”无效”,怎么改啊?
楼主着段代码是干什么用的?重写吗?
{
public partial class Form1 : Form
{
private string FileName = "a.txt";
private string FileContent;
}
public class EventArgs
{
public EventArgs.EventArgrs();
}
}