0

テキストを特定の形式で RichTextBox に追加し、メッセージのみに色を付ける関数があります。これは機能です:

 internal void SendChat(Color color, string from, string message)
        {
            if (rtbChat.InvokeRequired)
            {
                rtbChat.Invoke(new MethodInvoker(() => SendChat(color, from, message)));
                return;
            }

            string Text = String.Format("[{0}] {1}: {2}", DateTime.Now.ToString("t"), from, message);
            rtbChat.AppendText(Text);
            rtbChat.Find(message);
            rtbChat.SelectionColor = color;

            rtbChat.AppendText("\r\n");

            rtbChat.ScrollToCaret();
        }

出力は次のようになります。

[12:21 AM] Tester: Hello!

ただし、2文字などの短い文章を入力すると、色が表示されない場合と表示される場合があります。それは Selection Color プロパティに関係していると思います..それを行う、または修正するためのより良い方法はありますか?

4

2 に答える 2