简体   繁体   English

如何在 RichTextBox 中显示 ★ 符号

[英]How to display the ★ symbols in RichTextBox

I have tried to create the RTF text from html when try this my html content have the text(★).我试图从 html 创建 RTF 文本,当我的 html 内容有文本(★)时。 In my RTF text has mentioned below,在我的 RTF 文本中提到过,

string rtf = @"{\rtf1{\fonttbl{\f0\froman Times New Roman;}{\f1\fnil Arial;}}{\colortbl;\red238\green122\blue3;}{{\pard {\f1 \sl240\slmult1 {\b\fs24\par \qc \cf1 {XhtmlCells}\par}{\b\fs20\par \qc \cf1 {★★★✩✩}\par}{{XhtmlCells use the }{\b { RichTextBoxSupportsXHTML}}{ control from GotDotNet user samples to display XHTML formatted text inside a cell.}\par}}}}}";

I have tried to load this text in RichTextBox1.Rtf which will be shown the "?"我试图在 RichTextBox1.Rtf 中加载此文本,它将显示“?” instead of "★".而不是“★”。

Can you please suggest me how to display this star symbol in RichTextBox.你能建议我如何在 RichTextBox 中显示这个星号。 Thanks in advance提前致谢

The parser will see the "Times New Roman" font at the beginning of your string and choke.解析器将在字符串的开头看到“Times New Roman”字体并阻塞。

Try this one:试试这个:

{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1031{\fonttbl{\f0\fnil\fcharset1 Segoe UI Symbol;}{\f1\fnil\fcharset0 Calibri;}}
{\*\generator Riched20 10.0.17134}\viewkind4\uc1 
\pard\sa200\sl276\slmult1\f0\fs22\lang7\u9733?\f1\par
}

Seriously, it is probably a matter of font and character set.说真的,这可能是字体和字符集的问题。

try:尝试:

richTextBox1.Font = new Font("Arial", 14);  
richTextBox1.Text = "Special character: \u20ac";

What .Net framework version are you targeting?您的目标是什么 .Net 框架版本? I'm guessing something prior to 4.7.我在猜测 4.7 之前的东西。

What you're seeing is a limitation of the RichTextBox being based on RICHEDIT20W with versions prior to .Net 4.7.您所看到的是基于 RICHEDIT20W 和 .Net 4.7 之前版本的 RichTextBox 的限制。 With the 4.7.x releases, the default switched to RICHEDIT50W.在 4.7.x 版本中,默认切换到 RICHEDIT50W。

Easiest solution is to just switch to a 4.7.x framework version, as long as that's an option.最简单的解决方案是切换到 4.7.x 框架版本,只要这是一个选项。 If you have to use an older framework for whatever reason, you can follow something like this example (code copied below for posterity) to switch to the RICHEDIT50W editor.如果您出于某种原因必须使用较旧的框架,您可以按照此示例(为后代复制下面的代码)来切换到 RICHEDIT50W 编辑器。 It's been around since the days of XP so it should be available pretty much everywhere anymore.它从 XP 时代就已经存在,所以现在应该几乎可以在任何地方使用了。

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);

protected override CreateParams CreateParams
{
    get
    {
       CreateParams cparams = base.CreateParams; 
       if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
       {
          cparams.ClassName = "RICHEDIT50W";
       }
       return cparams;
     }
}

I have not used the above method, but what you're experiencing is a common issue.我没有使用上述方法,但您遇到的是一个常见问题。 Searching for RichTextEdit, RICHEDIT20W, and/or RICHEDIT50W will get you far more than you've ever wanted to know about the internals of a rich text editor.搜索 RichTextEdit、RICHEDIT20W 和/或 RICHEDIT50W 会让您获得远超您想了解的富文本编辑器内部结构的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM