英文:
How i can disable the rich text effect of richtextbox?
问题
如何禁用`richtextbox`的富文本效果?我正在使用Windows Forms,C#,.Net Framework 4.8并尝试制作一个记事本应用程序。但是富文本效果很糟糕。
示例:
![外观](https://i.stack.imgur.com/oTcPN.png)
那个语法高亮和图片。
我测试了以下代码(来自ChatGpt)
```csharp
richTextBox1.Rtf = "";
if (Clipboard.ContainsText(TextDataFormat.Rtf))
{
richTextBox1.Rtf = Clipboard.GetText(TextDataFormat.Rtf);
}
else if (Clipboard.ContainsText(TextDataFormat.Text))
{
richTextBox1.Text = Clipboard.GetText(TextDataFormat.Text);
}
第一个代码,它仍然可以显示图片,但没有语法高亮。我不想使用这个。第二个代码,我和第一个做了相同的操作,我不记得代码的输出。
<details>
<summary>英文:</summary>
How I can disable the rich text effect of `richtextbox`? I am using Windows Forms, C#, .Net Framework 4.8 and I am trying to make a Notepad app. And richtext effect is so bad.
Example:
![Look](https://i.stack.imgur.com/oTcPN.png)
That syntax highlighting and images.
I test these (codes from ChatGpt)
richTextBox1.Rtf = "";
if (Clipboard.ContainsText(TextDataFormat.Rtf))
{
richTextBox1.Rtf = Clipboard.GetText(TextDataFormat.Rtf);
}
else if (Clipboard.ContainsText(TextDataFormat.Text))
{
richTextBox1.Text = Clipboard.GetText(TextDataFormat.Text);
}
1st code, it still can show images but not syntax highlighting. and I do not want use this. 2nd code, I did same with 1st I dont remember that outputs of code.
</details>
# 答案1
**得分**: 1
```plaintext
"[RTF](https://en.wikipedia.org/wiki/Rich_Text_Format)" 代表“富文本格式” - 文本加上格式(如颜色和字体)和图像。
如果你只对纯文本版本感兴趣,那就不要费心获取RTF版本,只需使用剪贴板数据的纯文本版本。
所以将那些 `if` 替换为只有
```csharp
richTextBox1.Text = Clipboard.GetText(TextDataFormat.Text);
这样你只会从剪贴板中获取纯文本版本,并用它来填充你的 richTextBox 控件。
<details>
<summary>英文:</summary>
"[RTF](https://en.wikipedia.org/wiki/Rich_Text_Format)" stands for "Rich Text Format" - text PLUS formatting (like colors and fonts) and images.
If all you are interested in is the plain text version, then don't bother getting the RFT version, just use the plain text version of the clipboard's data.
So replace those `if`s with just
richTextBox1.Text = Clipboard.GetText(TextDataFormat.Text);
That way you only get the plain-text version from the clipboard and use that to fill your richTextBox control.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论