下面一段代码(c#中关于打开文件对话框),编译时没有错误,可是执行时发生如图显示的错误,求大神指点!
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;
namespace WindowsFormsApplication16
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
openFileDialog1.DefaultExt = "txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(openFileDialog1.FileName);
}
}
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication16
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
openFileDialog1.DefaultExt = "txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(openFileDialog1.FileName);
}
}
}
} 展开
3个回答
展开全部
改成这样:richTextBox1.LoadFile(FileName, RichTextBoxStreamType.UnicodePlainText);
首先你要熟悉richTextBox1.LoadFile可以载入的文件格式
如果是txt格式 你要unicode编码保存才能打开,不然就会报错
首先你要熟悉richTextBox1.LoadFile可以载入的文件格式
如果是txt格式 你要unicode编码保存才能打开,不然就会报错
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请采用下面的形式打开文本文件并显示内容:
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
openFileDialog1.DefaultExt = "txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader sReader = new StreamReader(openFileDialog1.FileName, Encoding.Default);
this.richTextBox1.Text = sReader.ReadToEnd();
}
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
openFileDialog1.DefaultExt = "txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader sReader = new StreamReader(openFileDialog1.FileName, Encoding.Default);
this.richTextBox1.Text = sReader.ReadToEnd();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
后面的冒号 换成 英 那个冒号试试 这种错误我以前翻的多了
呵呵
呵呵
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询