我正在尝试将彩色文本“RTF”发送到richedit20w
这是我的代码:
public static void SendColoredMSG(string Text, string title)
{
RichTextBox richtext = new RichTextBox();
richtext.SelectAll();
richtext.Font = new Font(richtext.SelectionFont.FontFamily, 12, FontStyle.Bold);
richtext.SelectionColor = System.Drawing.Color.Green;
IntPtr hRich = GetRichHandle(title, true);
//here if i replace richtext.rtf with richtext.text it sends the text fine but without color.
SendMessage(hRich, WM_SETTEXT, 0, new StringBuilder(richtext.Rtf));
SendMessage(hRich, WM_KEYDOWN, 13, 0);
}
问题是我是否用以下方法调用此方法:
SendColoredMSG("test","some Title");
它会输入:
{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang3073{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}
{\colortbl ;\red0\green128\blue0;}
\viewkind4\uc1\pard\ltrpar\cf1\b\f0\fs24 test\cf0\par
}
我不确定为什么会发生这种情况以及我应该采取哪些措施才能使其发挥作用。