开发者

Rich textbox font turning into selected text font

Context. Chat server.

As such I need the users to have his own font and Colour

Let's say currently the chatbox has 2 lines now

Red line
Green line

And red user types in another line. The whole RichTextBox becomes red. i.e

Red line
Red line //This line was suppose to be green
Red line

This is my function to add a new line to the RichTextBox. String s is for debugging purpose

void OutBox(RichTextBox textBox, string user, string msg, string strFont, string strColour)
        {
            int start = textBox.TextLength;
            textBox.Text += user + " says: " + msg;
            int end = textBox.TextLength;
            textBox.Select(start, end - start);
            Font font = (Font)fc.ConvertFromString(strFont);
            Color colour = (Color)cc.ConvertFromString(strColour);
            string s = textBox.SelectedText;
            textBox.SelectionFont = font;
            textBox.Sele开发者_如何学GoctionColor = colour;
        }

Any idea what's wrong? String s shows that it did indeed select only the newline.


void OutBox(RichTextBox textBox, string user, string msg, string strFont, string strColour)
        {
            string s = user + " says: " + msg + "\r";
            textBox.AppendText(s);
            textBox.SelectionStart = textBox.TextLength - s.Length;
            textBox.SelectionLength = s.Length;
            Font font = (Font)fc.ConvertFromString(strFont);
            Color colour = (Color)cc.ConvertFromString(strColour);
            string s1 = textBox.SelectedText;
            textBox.SelectionFont = font;
            textBox.SelectionColor = colour;
        }

Apparently using textBox.AppendText instead of textBox.Text += solves the problem.

Anyone know why?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜