实时聊天界面文字颜色更改,消息发送人进行高亮显示。
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace 软件系统客户端模版.UIControls
|
||||
{
|
||||
@@ -40,6 +41,13 @@ namespace 软件系统客户端模版.UIControls
|
||||
public void DealwithReceive(string str)
|
||||
{
|
||||
richTextBox1.AppendText(str + Environment.NewLine);
|
||||
int length = str.IndexOf(Environment.NewLine) + 1;
|
||||
if (length > 0)
|
||||
{
|
||||
richTextBox1.Select(richTextBox1.Text.Length - str.Length + 1, length);
|
||||
richTextBox1.SelectionColor = Color.Blue;
|
||||
}
|
||||
ScrollToDown();
|
||||
}
|
||||
/// <summary>
|
||||
/// 新增聊天的历史记录
|
||||
@@ -48,11 +56,34 @@ namespace 软件系统客户端模版.UIControls
|
||||
public void AddChatsHistory(string str)
|
||||
{
|
||||
richTextBox1.Text = str;
|
||||
MatchCollection mc = Regex.Matches(str, @"\u0002.+\r\n");
|
||||
int indexrow = 0;
|
||||
if (str != "")
|
||||
{
|
||||
foreach (Match m in mc)
|
||||
{
|
||||
richTextBox1.Select(m.Index - indexrow * 2, m.Length - 2);
|
||||
richTextBox1.SelectionColor = Color.Blue;
|
||||
indexrow++;
|
||||
}
|
||||
}
|
||||
ScrollToDown();
|
||||
}
|
||||
|
||||
public void InputFocus()
|
||||
{
|
||||
textBox1.Focus();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 光标滚动到最底端
|
||||
/// </summary>
|
||||
public void ScrollToDown()
|
||||
{
|
||||
richTextBox1.SelectionStart = richTextBox1.Text.Length;
|
||||
richTextBox1.ScrollToCaret();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user