富文本框字体变成选定的文本字体
语境。聊天服务器。
因此,我需要用户拥有自己的字体和颜色
假设目前聊天框有 2 行
Red line
Green line
,红色用户在另一行中键入。整个 RichTextBox 变成红色。即
Red line
Red line //This line was suppose to be green
Red line
这是我向 RichTextBox 添加新行的函数。 String s 用于调试目的
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.SelectionColor = colour;
}
知道出了什么问题吗? String s 表明它确实只选择了换行符。
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.SelectionColor = colour;
}
Any idea what's wrong? String s shows that it did indeed select only the newline.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然使用 textBox.AppendText 而不是 textBox.Text += 解决了问题。
有人知道为什么吗?
Apparently using textBox.AppendText instead of textBox.Text += solves the problem.
Anyone know why?