【发布时间】:2021-04-19 12:15:37
【问题描述】:
我的应用有问题。我这样做是为了用我的应用程序双击打开文件:
public void ProcessText()
{
Path = Args[Args.Length - 1];
System.Windows.Forms.RichTextBox TB = new System.Windows.Forms.RichTextBox();
TB.Text = Path;
ContentTextBox.Text = System.IO.File.ReadAllText(TB.Text);
if (Args.Length == 1)
ContentTextBox.Text = ET;
}
我正在尝试使用注册表在我的应用程序中打开一个文件,它可以工作,但是当我尝试读取富文本格式时,它会显示:
{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Segoe UI;}{\f1\fnil Segoe UI;}} {\colortbl;\red255\green255\blue255;} {*\generator Riched20 10.0.19041}\viewkind4\uc1 \pard\cf1\f0\fs18 gtfyrdetfyguhkiljoulhykgtjfrhdegsw\f1\par }
不管这意味着什么……
我试图让它看起来像这样:
"tgyhjumki,ujhytgrfghbnjmk"
我使用了打开文件对话框中的代码:
ContentTextBox.LoadFile(OFD.FileName);
这就是它最终的样子:
public void ProcessText()
{
Path = Args[Args.Length - 1];
System.Windows.Forms.RichTextBox TB = new System.Windows.Forms.RichTextBox();
TB.Text = Path;
ContentTextBox.LoadFile(TB.Text);
if (Args.Length == 1)
ContentTextBox.Text = ET;
}
使用此代码后,它告诉我有一个错误:System.ArgumentException: 'File format is not valid.'
请帮我在不使用注册表编辑器的情况下解决此问题
【问题讨论】:
-
测试框中的编码是Windows Encoding 1252,所以要正常显示需要支持1252编码的字体。
-
它不允许我更改字体。我需要 C# 代码中的解决方案
-
你是如何创建文件的?
-
您需要设置 RTF 属性,而不是文本!你看到的是原始的 RTF 内容,即各种花括号中的命令..
-
System.ArgumentException: '路径中有非法字符。' - 这就是当我使用 Rtf 而不是 Text 时它向我展示的内容
标签: c# visual-studio winforms exception registry