我的程序如下
private void OpenFile()
{
if(lvFiles.SelectedItems.count<=0)
{
MessageBox.Show(this,"请先选择要打开的文件!","打开文件",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
ListViewItem lvi=lvFiles.SelevtedItems[0];
if((Path.GetExtension(lvi.Text)).ToLower()!=".txt")
{
MessageBox.Show(this,"只能打开文本文件!","打开文件错误",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
ContentForm fileForm=new ContenForm();
fileForm.Text="查看文件内容"+lvi.Text;
string filename=tvDir.SelectedNode.FullPath+"\\"+
lvFiles.SelectedItems[0].Text;
StreamReader sr=new StreamReader(filename);
ArrayList lines=new ArrayList();
while(sr.Peek()!=-1)
{
lines.Add(sr.ReadLine());
}
fileForm.txtContent.Lines=(string[])lines.ToArray(Type.GetType("System.string"));
sr.Close();
fileForm.txtContent.Select(0,0);
fileForm.ShowDialog(this);
}
它提示C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(421): 命名空间并不直接包含诸如字段或方法之类的成员
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(429): 应输入标识符
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(439): 应输入标识符
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(446): 应输入标识符
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(446): 应输入 class、delegate、enum、interface 或 struct
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(450): 应输入类型、命名空间定义或文件尾
private void OpenFile()
{
if(lvFiles.SelectedItems.count<=0)
{
MessageBox.Show(this,"请先选择要打开的文件!","打开文件",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
ListViewItem lvi=lvFiles.SelevtedItems[0];
if((Path.GetExtension(lvi.Text)).ToLower()!=".txt")
{
MessageBox.Show(this,"只能打开文本文件!","打开文件错误",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
ContentForm fileForm=new ContenForm();
fileForm.Text="查看文件内容"+lvi.Text;
string filename=tvDir.SelectedNode.FullPath+"\\"+
lvFiles.SelectedItems[0].Text;
StreamReader sr=new StreamReader(filename);
ArrayList lines=new ArrayList();
while(sr.Peek()!=-1)
{
lines.Add(sr.ReadLine());
}
fileForm.txtContent.Lines=(string[])lines.ToArray(Type.GetType("System.string"));
sr.Close();
fileForm.txtContent.Select(0,0);
fileForm.ShowDialog(this);
}
它提示C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(421): 命名空间并不直接包含诸如字段或方法之类的成员
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(429): 应输入标识符
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(439): 应输入标识符
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(446): 应输入标识符
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(446): 应输入 class、delegate、enum、interface 或 struct
C:\Documents and Settings\hwh\My Documents\Visual Studio Projects\WindowsApplication3\WindowsApplication3\Form1.cs(450): 应输入类型、命名空间定义或文件尾
Projects\WindowsApplication3\WindowsApplication3\Form1.cs(421):
如何知道哪一行是第421行阿
private void OpenFile()为421行
ListViewItem lvi=lvFiles.SelevtedItems[0];为429行
lvFiles.SelectedItems[0].Text;为439行
fileForm.txtContent.Lines=(string[])lines.ToArray(Type.GetType("System.string"));为446行