c#做记事本,怎么打开正常的txt文件会出错
,自己通过那记事本保存的文档再打开可以,但是用window的记事本打开用那记事本保存的文件是乱码打开,保存代码如下//打开文件privatevoidopenToolStr...
,自己通过那记事本保存的文档再打开可以,但是用window的记事本打开用那记事本保存的文件是乱码 打开,保存代码如下
//打开文件
private void openToolStripMenuItem_Click_1(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
DialogResult result = open.ShowDialog();
if (result == DialogResult.OK)
{
fileName = open.FileName;
open.Filter = "Text(*.txt)|*.txt|RichText(*.rtf)|*.rtf|所有文件|*.*";
richTextBox.LoadFile(fileName);
}
//保存文件
private void saveFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (fileName == null)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Text(*.txt)|*.txt|RichText(*.rtf)|*.rtf|所有文件|*.*";
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
fileName = dialog.FileName;
richTextBox.SaveFile(fileName); 展开
//打开文件
private void openToolStripMenuItem_Click_1(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
DialogResult result = open.ShowDialog();
if (result == DialogResult.OK)
{
fileName = open.FileName;
open.Filter = "Text(*.txt)|*.txt|RichText(*.rtf)|*.rtf|所有文件|*.*";
richTextBox.LoadFile(fileName);
}
//保存文件
private void saveFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (fileName == null)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Text(*.txt)|*.txt|RichText(*.rtf)|*.rtf|所有文件|*.*";
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
fileName = dialog.FileName;
richTextBox.SaveFile(fileName); 展开
2个回答
展开全部
记事本文件,是 plaintext 模式,你的 richtextbox 使用方法有误。正确的代码如下:
//打开文件
private void openToolStripMenuItem_Click_1(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Text(*.txt)|*.txt|RichText(*.rtf)|*.rtf|所有文件|*.*";
DialogResult result = open.ShowDialog();
if (result == DialogResult.OK)
{
fileName = open.FileName;
richTextBox.LoadFile(fileName, RichTextBoxStreamType.PlainText);
}
//保存文件
private void saveFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (fileName == null)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Text(*.txt)|*.txt|RichText(*.rtf)|*.rtf|所有文件|*.*";
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
fileName = dialog.FileName;
richTextBox.SaveFile(fileName, RichTextBoxStreamType.PlainText);
}
//打开文件
private void openToolStripMenuItem_Click_1(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Text(*.txt)|*.txt|RichText(*.rtf)|*.rtf|所有文件|*.*";
DialogResult result = open.ShowDialog();
if (result == DialogResult.OK)
{
fileName = open.FileName;
richTextBox.LoadFile(fileName, RichTextBoxStreamType.PlainText);
}
//保存文件
private void saveFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (fileName == null)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Text(*.txt)|*.txt|RichText(*.rtf)|*.rtf|所有文件|*.*";
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
fileName = dialog.FileName;
richTextBox.SaveFile(fileName, RichTextBoxStreamType.PlainText);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询